This page has been translated automatically.
UnigineScript
The Language
Engine Library
Node-Related Classes
GUI-Related Classes
Plugins Library
High-Level Systems
Samples
C++ API
API Reference
Integration Samples
Usage Examples
C++ Plugins
Content Creation
Materials
Unigine Material Library
Tutorials
注意! 这个版本的文档是过时的,因为它描述了一个较老的SDK版本!请切换到最新SDK版本的文档。
注意! 这个版本的文档描述了一个不再受支持的旧SDK版本!请升级到最新的SDK版本。

Math Random Functions

float rand ()

Generate a floating point random value in range [0,1). The function returns system rand() / RAND_MAX.

Return value

A pseudo-random number between 0.0 and 1.0.

Examples

Source code (UnigineScript)
forloop(int i = 0; 4) {
	printf("%s\n",typeinfo(rand()));
}
/*
result is:
float: 0.510393
float: 0.638238
float: 0.406844
float: 0.407974
*/

variable rand (variable from, variable to)

Generate a random value in range [to,from). For vectors values are obtained per component.

Arguments

  • variable from - From value. Can be the following types:
  • variable to - To value. Can be the following types:
    • int, long, float or double if the first argument is either int, float or double.
    • string if the first argument is int:
      • If a string is empty, it will equal to int(0).
      • If a string is nonempty, it will equal to int(1).
    • vec3 or dvec3 if the first argument is vec3
    • vec4 or dvec4 if the first argument is vec4
    • dvec3 if the first argument is dvec3
    • dvec4 if the first argument is dvec4
    • ivec3 if the first argument is ivec3
    • ivec4 if the first argument is ivec4

Return value

A pseudo-random number between from and to.

Examples

Source code (UnigineScript)
printf("%s\n",typeinfo(rand(-2,3)));
printf("%s\n",typeinfo(rand(-3.0,2)));
printf("%s\n",typeinfo(rand(vec3(-1,-2,-3),vec3(1,2,3))));
/*
result is:
int: 1
float: 1.5561
vec3: 0.19138 1.81164 -0.688218
*/

void srand (int seed)

Set a new sequence of random numbers. Function calls system srand() function.

Arguments

  • int seed - Seed value for system random number generator.
Last update: 2017-07-03
Build: ()