mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 06:08:41 +01:00
Fixed Random.sample(list, count) for small number of samples (#714)
Closes #713
This commit is contained in:
committed by
underscorediscovery
parent
53cf6f511b
commit
186a8c7c13
@ -51,7 +51,7 @@ foreign class Random {
|
||||
sample(list, count) {
|
||||
if (count > list.count) Fiber.abort("Not enough elements to sample.")
|
||||
|
||||
// There at (at least) two simple algorithms for choosing a number of
|
||||
// There are (at least) two simple algorithms for choosing a number of
|
||||
// samples from a list without replacement -- where we don't pick the same
|
||||
// element more than once.
|
||||
//
|
||||
@ -76,7 +76,7 @@ foreign class Random {
|
||||
// Find an index that we haven't already selected.
|
||||
var index
|
||||
while (true) {
|
||||
index = int(count)
|
||||
index = int(list.count)
|
||||
if (!picked.containsKey(index)) break
|
||||
}
|
||||
|
||||
|
||||
@ -53,7 +53,7 @@ static const char* randomModuleSource =
|
||||
" sample(list, count) {\n"
|
||||
" if (count > list.count) Fiber.abort(\"Not enough elements to sample.\")\n"
|
||||
"\n"
|
||||
" // There at (at least) two simple algorithms for choosing a number of\n"
|
||||
" // There are (at least) two simple algorithms for choosing a number of\n"
|
||||
" // samples from a list without replacement -- where we don't pick the same\n"
|
||||
" // element more than once.\n"
|
||||
" //\n"
|
||||
@ -78,7 +78,7 @@ static const char* randomModuleSource =
|
||||
" // Find an index that we haven't already selected.\n"
|
||||
" var index\n"
|
||||
" while (true) {\n"
|
||||
" index = int(count)\n"
|
||||
" index = int(list.count)\n"
|
||||
" if (!picked.containsKey(index)) break\n"
|
||||
" }\n"
|
||||
"\n"
|
||||
|
||||
Reference in New Issue
Block a user