1.1.7 • Published 2 years ago

use-pseudo-random v1.1.7

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

Pseudo random number generator

This is a wrapper hook for a pseudo random number generator. (it also can do pure random) based on Prando library

How to Use

  const [ randomValue, getNext ] = usePseudoRandom()
  // randomValue = some random number from 0 to 1 with no options

  getNext()
  // now randomValue is updated with the next number

Options

Optionrequiredtypedescription
seednostring or numberseed used to generate the numbers
WholeNumbernobooleandictate if using a whole number or not
rangeno{ min: number, max: number }Between a min (inclusive) and a max (exclusive) for non whole numbers, inclusive for whole numbers

Use Pseudo Random Number

This hook returns a tuple of the random number and a function to get the next number.

  const [ randomValue, getNext ] = usePseudoRandom()
  // randomValue = some random number from 0 to 1 with no options

  getNext()
  // now randomValue is updated with the next number

Options for the random number generator can be passed in as an object.

  const [ randomValue, getNext ] = usePseudoRandom({
    seed: 'some seed', // text or number can be a seed
    wholeNumber: true,
    range: { min: 0, max: 10 }
  })

under the hood this is using the Prando library.

1.1.7

2 years ago

1.1.6

2 years ago

1.0.5

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago