Skip to Content
Learn Red ? Fundamentals of Red
book

Learn Red ? Fundamentals of Red

by Ivo Balbaert
May 2018
Beginner content levelBeginner
252 pages
6h 19m
English
Packt Publishing
Content preview from Learn Red ? Fundamentals of Red

Making random objects

The random function can work on any value of a simple type to return a random value of that type, for example:

random 100        ;== 71random 2.71       ;== 2.027808184808962random "house"    ;== "hsuoe"random 2018-02-13 ;== 23-Mar-1968

This command also has a few refinements:

  • To pick a random value from a series, use /only:
      random/only ["one" "two" "three" "four"]   ;== "three"
  • /seed restarts the random generator to obtain new random values between runs of the same code; the current time is a good seed. The following code uses this and then prints nine random numbers in a loop:
      random/seed now/time       loop 9 [          r: random 10           prin r prin space      ]                   ;1st run: == 4 5 3 5 7 9 3 10 10                          ;2nd run: == 10 8 10 2 3 1 4 2 1
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

How I Built a Personal Board of Directors With GenAI

How I Built a Personal Board of Directors With GenAI

Vipin Gupta
How to Become a Game-Changing Leader

How to Become a Game-Changing Leader

Douglas A. Ready, Alan Mulally
Why AI Demands a New Breed of Leaders

Why AI Demands a New Breed of Leaders

Faisal Hoque, Thomas Davenport, Erik Nelson

Publisher Resources

ISBN: 9781789130706Supplemental Content