Data type
Random
Generates pseudorandom numbers and directions.
About Random
The Random data type generates pseudorandom numbers and directions.
Constructors 1
Random.new
(seed: number)Returns a new pseudorandom generator using an optional seed.
Methods 6
NextInteger
(min: number, max: number) → numberReturns a pseudorandom integer uniformly distributed over[min, max].Returns a pseudorandom integer uniformly distributed over
[min, max], inclusive of both endpoints. Ifminis greater thanmax, the two values are swapped so the call still succeeds. Both arguments are truncated toward zero to whole numbers before sampling.NextNumber
() → numberReturns a pseudorandom number uniformly distributed over[0, 1].Returns a uniform pseudorandom real number in the range of 0 to 1, inclusive.
NextNumber
(min: number, max: number) → numberReturns a pseudorandom number uniformly distributed over[min, max].Returns a uniform pseudorandom real number in the range of
mintomax, inclusive.Shuffle
(tb: table) → ()Uniformly shuffles a table in-place.Uniformly shuffles the array part of
tbin-place usingNextIntegerto pick indices. If there are anynil"holes" in the array part of the table,Shufflethrows an error, since shuffling could change the length.The hash part of
tbis ignored. No metamethods oftbare invoked.The shuffle is defined to be a Fisher-Yates shuffle so the number of
NextIntegercalls is guaranteed to be consistent between engine versions for a given size of table.NextUnitVector
() → Vector3Returns a unit vector with a pseudorandom direction.Returns a unit vector with a pseudorandom direction. Vectors returned from this function are uniformly distributed over the unit sphere.
Clone
() → RandomReturns a new Random object with the same state as the original.Returns a new
Randomobject whose internal state is copied from the original. After cloning, both the original and the clone produce the same sequence of pseudorandom values going forward, but they advance independently — consuming a value from one does not affect the other.
Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.