Name |
Ceylon Random Platform Module |
---|---|
Category |
SDK
The Ceylon SDK |
Backends | JVM JavaScript |
Maven coordinates | org.ceylon-lang:ceylon.random |
Compatible Ceylon release |
JVM: 1.2.x, 1.3.x (latest) JavaScript: Unknown (10/0) |
Published | Aug 21, 2017 |
Stats |
Downloads (JVM): 1770 Downloads (JS): 274 Source downloads: 639 |
Authors |
John Vasileff |
License | Apache Software License |
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 } |
Dependencies | |
Usage |
import ceylon.random "1.3.3"; |
Module links |
Members Imported By Home Code repository Issue tracker Browse Download .car Download .js Download source archive Download module documentation View API documentation |