Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,11 +1,5 @@
|
|||
import std.stdio, std.random, std.algorithm;
|
||||
|
||||
double random01(ref Xorshift rng) {
|
||||
immutable r = rng.front / double(rng.max);
|
||||
rng.popFront;
|
||||
return r;
|
||||
}
|
||||
|
||||
struct SOfN(size_t n) {
|
||||
size_t i;
|
||||
int[n] sample = void;
|
||||
|
|
@ -14,7 +8,7 @@ struct SOfN(size_t n) {
|
|||
i++;
|
||||
if (i <= n)
|
||||
sample[i - 1] = item;
|
||||
else if (rng.random01 < (double(n) / i))
|
||||
else if (rng.uniform01 < (double(n) / i))
|
||||
sample[uniform(0, n, rng)] = item;
|
||||
return sample[0 .. min(i, $)];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue