Implement random
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import {expect, test} from 'bun:test'
|
||||
import Random from '.'
|
||||
|
||||
test('same result', async () => {
|
||||
const random1 = new Random(new Uint8Array(64))
|
||||
const a = await random1.random(128n)
|
||||
const a2 = await random1.random(128n)
|
||||
expect(a2).not.toBe(a)
|
||||
|
||||
const random2 = new Random(new Uint8Array(64))
|
||||
const b = await random2.random(128n)
|
||||
|
||||
expect(a).toBe(b)
|
||||
})
|
||||
|
||||
test('Different state, different number', async () => {
|
||||
const random1 = new Random(new Uint8Array(64))
|
||||
const a = await random1.random(128n)
|
||||
|
||||
const state = new Uint8Array(64)
|
||||
state[0] = 1
|
||||
const random2= new Random(state)
|
||||
const b = await random2.random(128n)
|
||||
|
||||
expect(a).not.toBe(b)
|
||||
})
|
||||
|
||||
test('New random is random', async () => {
|
||||
const r1 = new Random()
|
||||
const r2 = new Random()
|
||||
|
||||
const a = await r1.random(100n)
|
||||
const b = await r2.random(100n)
|
||||
|
||||
expect(b).not.toBe(a)
|
||||
})
|
||||
Reference in New Issue
Block a user