Difference between revisions of "Code Snippet: Random Fractions"

From Coder Merlin
(Created page with "= Generate a Random Fraction = == Swift == <syntaxhighlight lang="swift"> // Generate a fraction and print the result let fraction = Float.random(in: 0 ..< 1) print(fraction)...")
 
(Added Perl entry for random floats)
Line 9: Line 9:


== Python ==
== Python ==
== Perl ==
<syntaxhighlight lang="perl">
print rand(1), "\n";
</syntaxhighlight>

Revision as of 09:39, 13 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)

Python[edit]

Perl[edit]

print rand(1), "\n";