Difference between revisions of "Generate a random number"

From CodeCodex

m (Java)
(Implementations)
Line 5: Line 5:
 
  java.util.Random rand = new java.util.Random();
 
  java.util.Random rand = new java.util.Random();
 
  i = rand.nextInt(n+1);
 
  i = rand.nextInt(n+1);
 +
</pre>
 +
===OCaml===
 +
<pre>
 +
# Random.int 15;;
 +
- : int = 9
 
</pre>
 
</pre>
  
  
 
[[Category:Java]]
 
[[Category:Java]]

Revision as of 10:01, 18 August 2006

Implementations

Java

Generate a random int from 0 to n

 java.util.Random rand = new java.util.Random();
 i = rand.nextInt(n+1);

OCaml

# Random.int 15;;
- : int = 9