Implement random

This commit is contained in:
2024-06-10 09:45:25 +02:00
parent 5baff97de9
commit aea465d113
3 changed files with 108 additions and 1 deletions
+36
View File
@@ -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)
})