Fixed Random.sample(list, count) for small number of samples (#714)

Closes #713
This commit is contained in:
Thorbjørn Lindeijer
2019-12-12 00:40:07 +01:00
committed by underscorediscovery
parent 53cf6f511b
commit 186a8c7c13
2 changed files with 4 additions and 4 deletions

View File

@ -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
}

View File

@ -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"