mirror of
https://github.com/corda/corda.git
synced 2025-01-22 12:28:11 +00:00
implement Random.nextBytes and Random.nextLong
This commit is contained in:
parent
a16a00a7fb
commit
066714933c
@ -58,6 +58,21 @@ public class Random {
|
||||
return next(32);
|
||||
}
|
||||
|
||||
public void nextBytes(byte[] bytes) {
|
||||
final int length = bytes.length;
|
||||
for (int i = 0; i < length;) {
|
||||
int r = nextInt();
|
||||
for (int j = Math.min(length - i, 4); j > 0; --j) {
|
||||
bytes[i++] = (byte) r;
|
||||
r >>= 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long nextLong() {
|
||||
return ((long) next(32) << 32) + next(32);
|
||||
}
|
||||
|
||||
public double nextDouble() {
|
||||
return (((long) next(26) << 27) + next(27)) / (double) (1L << 53);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user