MCPcopy Create free account
hub / github.com/R-js/libRmath.js / rbits

Function rbits

src/lib/rng/utils.ts:25–37  ·  view source on GitHub ↗
(bits: number, unif_rand: IRNG)

Source from the content-addressed store, hash-verified

23}
24
25function rbits(bits: number, unif_rand: IRNG) {
26 let v = 0n;
27
28 for (let n = 0; n <= bits; n += 16) {
29 // FIXME: should this not be "*65535" ?, its ok, 65534 would be an error!!! (as some part of the range would not be reachable)
30 // but 65536 not matter so much
31 const ran = unif_rand.random();
32 const v1 = new Int32Array([trunc(ran * 65536)]);
33 v = 65536n * v + BigInt(v1[0]); //
34 }
35 // mask out the bits in the result that are not needed
36 return v & ((1n << BigInt(bits)) - 1n);
37}
38
39function R_unif_index_0(dn: number, unif_rand: IRNG): number {
40 const cut = unif_rand.cut;

Callers 1

R_unif_indexFunction · 0.85

Calls 1

randomMethod · 0.65

Tested by

no test coverage detected