kedoska / engine-blackjack

Javascript library to make blackjack engines
GNU General Public License v2.0
33 stars 29 forks source link

expose getRandom #24

Closed kedoska closed 7 years ago

kedoska commented 7 years ago

this is just in case you want to attach a better/different algo to get numbers.

const crypto = require('crypto')
const getRandom = (min, max) => {
  let number
  const range = max - min + 1
  do
  {
    const buffer = crypto.randomBytes(4)
    number = buffer.readUInt8(0)
    console.log(number)
  }
  while (number >= Number.MAX_VALUE - (Number.MAX_VALUE % range))
  number %= range
  return number + min
}

Signed-off-by: Marco Casula mc@clickbit.net