LinusU / react-native-get-random-values

A small implementation of `getRandomValues` for React Native
MIT License
354 stars 48 forks source link

How to get simple random number within a range? #52

Closed anniewey closed 1 year ago

anniewey commented 1 year ago

How to get random number between 1 to 10? To replace Math.random()

LinusU commented 1 year ago

This is outside of the scope of this library.

I would recommend searching/posting on Stack Overflow. From a quick glance, this answer seems to do it the way I'd imagine you should do it: https://stackoverflow.com/a/55544949/148072

It's easy to accidentally introduce bias when going to a specific integer range, so be sure to read up properly and maybe find a library that does this on top of getRandomValues.