MCPcopy Create free account
hub / github.com/MaxBittker/rs-sdk / nextInt

Method nextInt

server/engine/src/util/JavaRandom.ts:85–104  ·  view source on GitHub ↗
(bound?: number)

Source from the content-addressed store, hash-verified

83
84 // generate exclusive random number within bound
85 nextInt(bound?: number) {
86 if (bound === undefined) {
87 return next_signed(32);
88 }
89
90 checkIsPositiveInt(bound, 0x7fffffff);
91
92 // special case if bound is a power of two
93 if ((bound & -bound) === bound) {
94 const r = next(31) / p2_31;
95 return ~~(bound * r);
96 }
97
98 let bits, val;
99 do {
100 bits = next(31);
101 val = bits % bound;
102 } while (bits - val + (bound - 1) < 0);
103 return val;
104 }
105
106 nextLong() {
107 const msb = BigInt(next_signed(32));

Callers

nothing calls this directly

Calls 3

next_signedFunction · 0.70
checkIsPositiveIntFunction · 0.70
nextFunction · 0.70

Tested by

no test coverage detected