Garry's Mod Wiki

util.SharedRandom

  number util.SharedRandom( string uniqueName, number min, number max, number additionalSeed = 0 )

Description

Generates a random float value that should be the same on client and server.

This function is best used in a predicted hook

Arguments

1 string uniqueName
The seed for the random value
2 number min
The minimum value of the random range
3 number max
The maximum value of the random range
4 number additionalSeed = 0
The additional seed

Returns

1 number
The random float value

Example

Example usage of the function. Generates some random values.

print( util.SharedRandom( "23", 0, 100 ) ) print( util.SharedRandom( "23", 0, 100 ) ) print( util.SharedRandom( "23", 0, 100, 0 ) ) print( util.SharedRandom( "23", 0, 100, 1337 ) ) print( util.SharedRandom( "lol", 0, 100, 1337 ) )
Output:
15.979786317786 15.979786317786 15.979786317786 24.08124470342 78.480193614252