Crystal’s Random module provides pseudorandom number generation.
Some of the generated numbers may be different when you run the sample.
See the Random module docs for references on other random quantities that Crystal can provide.
Crystal’s Random module is similar to Go’s math/rand/v2 package, but with some differences:
Crystal uses Random.new to create a new random number generator, while Go uses rand.New.
In Crystal, you can directly use Random.new.rand(100) to get a random integer between 0 and 99, while in Go you would use rand.IntN(100).
Crystal’s Random.new.rand returns a Float64 between 0 and 1, similar to Go’s rand.Float64().
Crystal doesn’t have a direct equivalent to Go’s NewPCG, but you can create a seeded random number generator using Random.new(seed).
The overall functionality is similar, allowing you to generate random integers, floats, and create seeded random number generators for reproducible sequences.