Skip to content

Commit 2d16a57

Browse files
committed
add an example of generating random numbers in an arbitrary range
1 parent 3e897aa commit 2d16a57

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

chapters/math/generating-random-numbers.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ percentile = Math.floor(Math.random() * 100)
2424
dice = Math.floor(Math.random() * 6) + 1
2525
1 <= dice <= 6
2626
# => true
27+
28+
max = 42
29+
min = -13
30+
range = Math.random() * (max - min) + min
31+
-13 <= range < 42
32+
# => true
2733
{% endhighlight %}
2834

2935
## Discussion

0 commit comments

Comments
 (0)