#Random Number

8 messages · Page 1 of 1 (latest)

stoic arch
#

which method is the best generate random number?

hallow maple
#

Field.random()

stoic arch
#

like between 1-10

hallow maple
#
const x: UInt32 = UInt32.from(Field.random().rangeCheckHelper(32))
        .mod(UInt32.from(10))
        .add(UInt32.from(1));
cobalt smelt
#

this is pseudo randomness at best, do not recommend using this for any production-ready randomness, for testing purposes should be fine!

misty ocean
#

How about Field(Math.ceil(10*Math.random()))

#

Can be changed to use crypto.getRandomValues pretty easily if you need it to be secure