Random: Difference between revisions

From Fancade Wiki
m (Make an infobox, and rework page)
m (Replace with Image templates)
 
Line 16: Line 16:
* The random block will generate a new value every time it is executed. To reuse the same random value, it should be stored in a [[Set Variable|variable]].
* The random block will generate a new value every time it is executed. To reuse the same random value, it should be stored in a [[Set Variable|variable]].
* Note that the output would be in decimal. To avoid this use a rounding operation, ideally [[floor]] and secondarily [[round]]. [[Ceiling]] also works but is scarcely used.
* Note that the output would be in decimal. To avoid this use a rounding operation, ideally [[floor]] and secondarily [[round]]. [[Ceiling]] also works but is scarcely used.
* The random block behaves inconsistently when used with [[wire splits]]: [[File:Random_inconsistency.png]]
* The random block behaves inconsistently when used with [[wire splits]]:
: {{Image|Random_inconsistency.png}}


== Examples ==
== Examples ==
Line 22: Line 23:
Either generate -1 or 1.
Either generate -1 or 1.


[[File:Random_-1_or_1.png]]
{{Image|Random_-1_or_1.png}}


Output a random integer with equal probability.
Output a random integer with equal probability.


[[File:Random_integer.png]]
{{Image|Random_integer.png}}


== Related ==
== Related ==

Latest revision as of 10:30, 22 May 2024

Random
Random.png
TypeScript block
ColliderNone
FolderMath
Ports
Inputs Min
Max
Outputs Random

A random number generator.

Notes

  • Port inputs default to 0 and 1 respectively.
  • The Min input is included while the Max input is excluded, meaning: if the min and max inputs are 0 and 5 respectively, it may generate a number within 0 to 5, possibly 0, but never 5.
  • The random block will generate a new value every time it is executed. To reuse the same random value, it should be stored in a variable.
  • Note that the output would be in decimal. To avoid this use a rounding operation, ideally floor and secondarily round. Ceiling also works but is scarcely used.
  • The random block behaves inconsistently when used with wire splits:
Random_inconsistency.png

Examples

Either generate -1 or 1.

Random_-1_or_1.png

Output a random integer with equal probability.

Random_integer.png

Related