Random: Difference between revisions

From Fancade Wiki
(Created page with "A number randomizer. File:Random1.png Inputs: * Min: The minimum amount the block chooses from. * Max: The maximum amount the block chooses from. Outputs: * Random: The randomly selected number. == Notes == * 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 exe...")
 
m (Replace with Image templates)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
A number randomizer.
{{Block
|image=Random.png
|type=s
|folder=Math
|input1={{Port|n|Min}}
|input2={{Port|n|Max}}
|output1={{Port|n|Random}}
}}


[[File:Random1.png]]
A [https://en.wikipedia.org/wiki/Pseudorandom_number_generator random number generator].


Inputs:
== Notes ==


* Min: The minimum amount the block chooses from.
* Port inputs default to 0 and 1 respectively.
* Max: The maximum amount the block chooses from.
* 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 [[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.
* The random block behaves inconsistently when used with [[wire splits]]:
: {{Image|Random_inconsistency.png}}


Outputs:
== Examples ==
 
* Random: The randomly selected [[number]].
 
== Notes ==
* 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 [[floor]], [[ceiling]], or [[round]] operators.
* The random block behaves inconsistently when used with [[wire splits]]. [[/uploads/inconsistent-random.jpg]]


== Examples ==
Either generate -1 or 1.


Either generate -1 or 1:
{{Image|Random_-1_or_1.png}}


[[File:Screenshot_2020-06-23-23-24-42-333_com.martinmagni.fancade.png]]
Output a random integer with equal probability.


-----
{{Image|Random_integer.png}}


[[File:Screenshot_2023_0327_105551.png]]
== Related ==


* [[Random Seed]]


[[Category:Blocks]]
[[Category:Blocks]]

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