Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!

Difference between revisions of "random"

From Quake Wiki

 
Line 1: Line 1:
====Syntax:====
+
''float'' '''random'''()
<code>float random()</code>
+
== Usage ==
====Parameters:====
+
Used for generating random numbers e.g. with weapon spread.
:None
+
 
====Returns:====
+
=== Return ===
:Returns a floating point value greater than or equal to 0 and less than 1.
+
Returns a floating point value in the range [0, 1]. The fact it can return 1 is an oversight and caution should be exercised if using it for array indices.
 +
 
 +
== Example ==
 +
// Adds anywhere from 0 to 32 extra map units to the range
 +
float checkRadius = 256 + 32 * random();
 +
entity head = findradius(pos, checkRadius);

Latest revision as of 01:39, 31 July 2023

float random()

Usage[edit]

Used for generating random numbers e.g. with weapon spread.

Return[edit]

Returns a floating point value in the range [0, 1]. The fact it can return 1 is an oversight and caution should be exercised if using it for array indices.

Example[edit]

// Adds anywhere from 0 to 32 extra map units to the range
float checkRadius = 256 + 32 * random();
entity head = findradius(pos, checkRadius);