Name |
Ceylon Random Platform Module |
---|---|
Description |
Ceylon Random provides:
To generate random numbers, create and use an instance of // Create a random number generator value random = DefaultRandom(); // Print a pseudorandom Float in the range 0.0 to 1.0: print (random.nextFloat()); Other simple methods include
print(random.nextElement(1..100)); // Sample output: 27 or select a random element from a print(random.nextElement(["heads", "tails"])); // Sample output: heads It is also possible to obtain an infinite stream of random values using the methods
For example, to simulate multiple rolls of a die: value diceStream => random.elements([*('⚀':6)]); print(diceStream.take(10)); // Sample output: { ⚂, ⚀, ⚀, ⚂, ⚀, ⚅, ⚁, ⚅, ⚅, ⚁ } Finally, print(randomize { for (suit in {"♠", "♥", "♦", "♣"}) for (rank in {"Ace", "King", "Queen", "Jack", *(10..2)*.string}) suit + rank }.take(5)); // sample output: { ♥6, ♣Queen, ♦King, ♥King, ♣10 } |
Category |
SDK
The Ceylon SDK |
Last Published | Aug 21, 2017 |
Stats |
Downloads (JVM): 4122 Downloads (JS): 830 Source downloads: 3034 |
Module links |
Home Code repository Issue tracker Imported By Browse |
1.3.3 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) | Published Aug 21, 2017 |
Browse |
View docs |
|
1.3.2 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) | Published Mar 1, 2017 |
Browse |
View docs |
|
1.3.1 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) | Published Nov 21, 2016 |
Browse |
View docs |
|
1.3.0 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) | Published Sep 15, 2016 |
Browse |
View docs |
|
1.2.2 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) | Published Mar 11, 2016 |
Browse |
View docs |
|
1.2.1 | JVM JavaScript JVM: 1.2.x, 1.3.x (latest) JavaScript: 1.2.1, 1.2.2, 1.3.x (latest) | Published Feb 11, 2016 |
Browse |
View docs |