From 13dd9b739ac76b2241d6901a9933553348134eba Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Thu, 22 Mar 2018 14:13:23 -0500 Subject: [PATCH] Add Seeding And Generating Random Integers as a reason til --- README.md | 3 ++- .../seeding-and-generating-random-integers.md | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 reason/seeding-and-generating-random-integers.md diff --git a/README.md b/README.md index 788255e..c4dd1f1 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/). For a steady stream of TILs from a variety of rocketeers, checkout [til.hashrocket.com](https://til.hashrocket.com/). -_647 TILs and counting..._ +_648 TILs and counting..._ --- @@ -473,6 +473,7 @@ _647 TILs and counting..._ - [Multi-Argument Functions As Syntactic Sugar](reason/multi-argument-functions-as-syntactic-sugar.md) - [Pattern Match On Exceptions](reason/pattern-match-on-exceptions.md) - [Quickly Bootstrap A React App Using Reason](reason/quickly-bootstrap-a-react-app-using-reason.md) +- [Seeding And Generating Random Integers](reason/seeding-and-generating-random-integers.md) - [String Interpolation With Integers And Sprintf](reason/string-interpolation-with-integers-and-sprintf.md) - [String Interpolation With Quoted Strings](reason/string-interpolation-with-quoted-strings.md) diff --git a/reason/seeding-and-generating-random-integers.md b/reason/seeding-and-generating-random-integers.md new file mode 100644 index 0000000..4f69405 --- /dev/null +++ b/reason/seeding-and-generating-random-integers.md @@ -0,0 +1,20 @@ +# Seeding And Generating Random Integers + +It is easy enough to generate a series of random numbers using the `Random` +module's `int` function. + +```reason +Random.int(10); +``` + +This will generate a random integer between 0 and 9. + +You may notice that the randomness is the same each time you run your +program. That is because you have fixed seed. To make sure you have a +different seed each time your program runs, you can initialize the random +number generator with something different at each run, such as the current +time. + +```reason +Random.init(int_of_float(Js.Date.now())); +```