GSC reference › Built-in
RandomFloat()
Built-in (engine)
Server
Math
Returns a random floating point number r, where 0 <= r < max
Signature
RandomFloat(<max>)
Parameters
| Name | Required? | Details |
|---|---|---|
| max | Required | The maximum floating point size |
Example (from Treyarch's docs)
if ( RandomFloat( 100 ) > 50 ) ...
Real uses in BO3's scripts
Called 195 times in the decompiled scripts. A few, zombies first:
- scripts/zm/_fx.gsc, line 94
wait(shotdelaybase + randomfloat(shotdelayrange)); - scripts/zm/_zm.gsc, line 6853
wait(0.5 + randomfloat(2)); - scripts/zm/_zm_ai_faller.gsc, line 372
if(!self zombie_faller_always_drop() && randomfloat(1) > 0.5) - scripts/zm/_zm_ai_napalm.gsc, line 947
wait(randomfloat(1.25)); - scripts/zm/_zm_ai_quadrotor.gsc, line 633
score = randomfloat(30);
Related built-ins
- RandomFloatRange()Returns a random floating point number r, where min <= r < max
- MapFloat()Returns a lerped value between <from> and <to> based on <time>.
- Float()Casts a string or an integer to a float
- LerpFloat()Returns a lerped value between <from> and <to> based on <time>
- GetDvarFloat()Gets the value of a dvar.
- IsFloat()Checks whether this entity/variable is a float
- StrIsFloat()Check if a string is a float.
- Int()Casts a floating point number or a string to an integer
- DistanceSquared()Returns the squared distance between two points - this is cheaper than the actual distance as it doesn't involve a square root
- RandomInt()Returns a random integer between 0 and max-1 inclusive
- RandomIntRange()Returns a random integer r, where min <= r < max
- AnglesToForward()Returns the forward vector corresponding to a set of angles.
New to GSC?
Start with the basics, or paste a compile error to get the fix.
Built-in descriptions, parameters and examples come from Treyarch's BO3 mod tools docs. Usage links point at shiversoftdev/t7-source (decompiled BO3 scripts).