Rnd: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
No edit summary
JwellsNB (talk | contribs)
Add javascript snippet
Line 5: Line 5:
Rnd returns a single-precision number from a random sequence between 0 and 1.  The value is always random: no seed needs to be supplied.
Rnd returns a single-precision number from a random sequence between 0 and 1.  The value is always random: no seed needs to be supplied.


== Example ==
== Example (Basic) ==


<pre>
<pre>
Line 22: Line 22:
   Print "Four random numbers:", Ret
   Print "Four random numbers:", Ret
End Sub
End Sub
</pre>
== Example (JavaScript) ==
<pre>
// Rnd Example
/* Rnd generates random numbers */
Random();
Random();
Random();
function Random() {
  var Ret, i;
  Ret = "";
  for(i = 1; i <= 4; i++) {
    Ret = Ret + (Math.floor(100 * rnd())+1);
  }
  NSB.Print("Four random numbers: " + Ret);
}
</pre>
</pre>



Revision as of 22:14, 19 May 2013

Rnd

Description

Rnd returns a single-precision number from a random sequence between 0 and 1. The value is always random: no seed needs to be supplied.

Example (Basic)

Rem Rnd Example
'Rnd generates random numbers
Random
Random
Random
 
Sub Random
   Dim Ret, i
   Ret = ""
   For i = 1 TO 4
      Ret = Ret&(Int(100 * Rnd) +1) & " "
   Next
   Print "Four random numbers:", Ret
End Sub

Example (JavaScript)

// Rnd Example
/* Rnd generates random numbers */

Random();
Random();
Random();

function Random() {
  var Ret, i;
  Ret = "";
  for(i = 1; i <= 4; i++) {
     Ret = Ret + (Math.floor(100 * rnd())+1);
  }
  NSB.Print("Four random numbers: " + Ret);
}

Output

Four random numbers: 6 71 1 19
Four random numbers: 33 28 4 51
Four random numbers: 33 28 4 51

Related Items