A fork from David Bau's seedrandom library with TypeScript support and ES module compatibility as well as worklets and no node dependencies
npm install @skoiy/seedrandomA TypeScript fork of David Bau's seedrandom library with TypeScript support and ES module compatibility as well as worklets and no node dependencies.
This library provides seeded random number generation for JavaScript/TypeScript applications, including React Native worklets.
``sh`
npm install @skoiy/seedrandom
for cross-platform compatibility
- No Node.js specific APIs requiredUsage
`typescript
import seedrandom from '@skoiy/seedrandom'// Create a seeded random number generator
const rng = seedrandom('my-seed')
// Generate random numbers
console.log(rng()) // 0.123456...
console.log(rng.int32()) // Random 32-bit integer
console.log(rng.quick()) // Quick random number
console.log(rng.double()) // Same as rng()
// Use with state saving
const rngWithState = seedrandom('seed', { state: true })
const state = rngWithState.state()
const restoredRng = seedrandom(state)
`API
$3
-
seed: String or number to seed the generator
- options: Configuration object or boolean for entropy
- callback: Optional callback functionReturns a PRNG function with additional methods.
$3
-
(): Returns a random number between 0 and 1
- int32(): Returns a random 32-bit integer
- quick(): Returns a quick random number
- double(): Alias for ()
- state(): Returns the current state (if enabled)Development
`sh
$ npm run dev
`Build
`sh
$ npm run build
`Test
`sh
$ npm run test
``