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


CoderMerlin™ proudly recommends:
HintIcon.png

Your purchase via these links helps keep  Coder Merlin™ 's orbuculum ablaze. As an Amazon Associate we earn from qualifying purchases. Thank you for your support!


Designed with pride in Silicon Valley, CA, USA