CMPT 166 Lecture Notes - Lecture 30: Stochastic Process, Heightmap, Decimal Mark
Document Summary
Processing provides a couple of functions for generating random numbers, the most basic being random. The random function has two forms: float a = random(22. 6, 58. 2); // sets a to be a random number that is. 58. 2 float b = random(500. 0); // sets b to be a random number that is. Here"s how you could print 5 random numbers, each from 1 to 10: int i = 0; while (i < 5) { float r = random(1, 10); println(r); i += 1; Here"s what one run of this code prints: Every time you run it you will (almost certainly!) get different numbers, e. g. 3. 9555728. Sometimes you might want to know what random numbers you will get. You can do this by setting the random number generators seed, e. g. randomseed(2563); int i = 0; while (i < 5) { float r = random(1, 10); println(r); i += 1;