Code Snippet: Random Fractions

From Coder Merlin
Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Generate a Random Fraction[edit]

Swift[edit]

// Generate a fraction and print the result
let fraction = Float.random(in: 0 ..< 1)
print(fraction)

Java[edit]

// Import the random class in java.util
Random random = new Random();

Perl[edit]

print rand(1), "\n";