Files
processing4/mobile/web/reference/API/random.xml
2005-01-27 06:48:42 +00:00

72 lines
1.5 KiB
XML

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<name>random()</name>
<category>Math</category>
<subcategory>Random</subcategory>
<usage>Web &amp; Application</usage>
<example>
<image>random_.jar</image>
<code>
for(int i=0; i&lt;100; i++) {
float r = random(50);
stroke(r*5);
line(50, i, 50+r, i);
}
</code>
</example>
<example>
<image>random_2.jar</image>
<code>
for(int i=0; i&lt;100; i++) {
float r = random(-50, 50);
stroke(abs(r*5));
line(50, i, 50+r, i);
}
</code>
</example>
<description>
Generates random numbers. Each time the <b>random()</b> function is called, it returns an unexpected value within the specified range. If one parameter is passed to the function it will return a <b>float</b> between zero and the value of the parameter. The function call <b>random(5)</b> returns values between 0 and 5. If two parameters are passed, it will return a <b>float</b> with a value between the the parameters. The function call <b>random(-5, 10.2)</b> returns values between -5 and 10.2. To convert a floating-point random number to an integer, use the <b>int()</b> function.
</description>
<syntax>
random(<c>value1</c>);
random(<c>value1</c>, <c>value2</c>);
</syntax>
<parameter>
<label>value1</label>
<description>int or float</description>
</parameter>
<parameter>
<label>value2</label>
<description>int or float</description>
</parameter>
<returns>float</returns>
<related>
noise()
</related>
<availability>1.0</availability>
<type>Function</type>
<partof>Core</partof>
</root>