Code Snippet: Random Fractions

From Coder Merlin
Revision as of 09:39, 13 September 2019 by Nerdofcode (talk | contribs) (Added Perl entry for random floats)
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)

Python[edit]

Perl[edit]

print rand(1), "\n";