A simple, fast pseudo-random number generator. Internally, it uses the well equidistributed long-period linear PRNG (WELL512a).
Each instance of the class generates a sequence of randomly distributed numbers based on the internal state of the object. The state is initialized from a seed. Two instances with the same seed generate the exact same sequence of numbers.
It must be imported from the random module:
import "random" for Random
Creates a new generator whose state is seeded based on the current time.
var random = Random.new()
Creates a new generator initialized with [seed]. The seed can either be a number, or a non-empty sequence of numbers. If the sequnce has more than 16 elements, only the first 16 are used. If it has fewer, the elements are cycled to generate 16 seed values.
Random.new(12345) Random.new("appleseed".codePoints)
Returns a floating point value between 0.0 and 1.0, including 0.0, but excluding 1.0.
var random = Random.new(12345) System.print(random.float()) 0.53178795980617 System.print(random.float()) 0.20180515043262 System.print(random.float()) 0.43371948658705
Returns a floating point value between 0.0 and end, including 0.0 but
excluding end.
var random = Random.new(12345) System.print(random.float(0)) 0 System.print(random.float(100)) 20.180515043262 System.print(random.float(-100)) -43.371948658705
Returns a floating point value between start and end, including start but
excluding end.
var random = Random.new(12345) System.print(random.float(3, 4)) 3.5317879598062 System.print(random.float(-10, 10)) -5.9638969913476 System.print(random.float(-4, 2)) -1.3976830804777
Returns an integer between 0 and end, including 0 but excluding end.
var random = Random.new(12345) System.print(random.int(1)) 0 System.print(random.int(10)) 2 System.print(random.int(-50)) -22
Returns an integer between start and end, including start but excluding
end.
var random = Random.new(12345) System.print(random.int(3, 4)) 3 System.print(random.int(-10, 10)) -6 System.print(random.int(-4, 2)) -2