Difference between revisions of "Ns rand"

From AOLserver Wiki
Jump to navigation Jump to search
(added link to java's random)
 
(One intermediate revision by one other user not shown)
Line 27: Line 27:
 
'''CAVEAT'''
 
'''CAVEAT'''
  
: [ns_rand 1] will always produce the result 0. [ns_rand 2] will produce the desired "coin flip" outcome of 0 or 1. This is standard with [http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html#nextInt(int) Java's Random implementation of nextInt] and most other random number libraries.
+
: [ns_rand 1] will always produce the result 0. [ns_rand 2] will produce the desired "coin flip" outcome of 0 or 1. This is standard with [http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html#nextInt(int) Java's java.util.Random implementation of nextInt] and most other random number libraries.
  
 
'''SEE ALSO'''
 
'''SEE ALSO'''
  
----
 
  
[[Category Documentation]] - [[Category Core Tcl API]]
+
[[Category:Documentation]] [[Category:Core Tcl API]]

Latest revision as of 19:56, 7 February 2009

Man page: http://aolserver.com/docs/tcl/ns_rand.html


NAME

ns_rand - Generate a random number

SYNOPSIS

ns_rand ?maximum?

DESCRIPTION

This command generates a cryptographically secure random number. If maximum is not specified, the random number returned is a floating-point value n such that 0.0 <= n < 1.0. If maximum is specified, it must be a positive integer between 1 and 2147483647, in which case ns_rand will return an integer value n such that 0 <= n <= max - 1.
Internally ns_rand is implemented with the drand48() and lrand48() standard library functions. An internal random seed is generated the first time ns_rand is called after the server starts.

EXAMPLES

   % ns_rand
   0.39938485692
   % ns_rand 10
   7

CAVEAT

[ns_rand 1] will always produce the result 0. [ns_rand 2] will produce the desired "coin flip" outcome of 0 or 1. This is standard with Java's java.util.Random implementation of nextInt and most other random number libraries.

SEE ALSO