Code Snippet: Random Fractions

From Coder Merlin™

Generate a Random Fraction

Swift

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

Java

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

Perl

print rand(1), "\n";