Difference between revisions of "Code Snippet: Random Fractions"

From Coder Merlin
(Added Perl entry for random floats)
Line 7: Line 7:
print(fraction)
print(fraction)
</syntaxhighlight>
</syntaxhighlight>
== Python ==


== Perl ==
== Perl ==

Revision as of 09:27, 19 September 2019

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)

Perl[edit]

print rand(1), "\n";