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

Method nextInt

server/webclient/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 this.nextSigned(32);
88 }
89
90 if (bound <= 0 || bound > 0x7fffffff) {
91 throw RangeError();
92 }
93
94 // special case if bound is a power of two
95 if ((bound & -bound) === bound) {
96 const r = this.next(31) / p2_31;
97 return ~~(bound * r);
98 }
99
100 let bits, val;
101 do {
102 bits = this.next(31);
103 val = bits % bound;
104 } while (((bits - val + (bound - 1)) | 0) < 0);
105 return val;
106 }
107

Callers

nothing calls this directly

Calls 3

next_signedFunction · 0.70
checkIsPositiveIntFunction · 0.70
nextFunction · 0.70

Tested by

no test coverage detected