Code Snippet: Random Fractions

From Coder Merlin
Jump to navigation Jump to search

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";


Designed with pride in Silicon Valley, CA, USA