|Pliant talk forum
Feature request: On a generating random numbers
|Message posted by maybe Marcus on 2002/07/24 14:10:33
|I need a mundane random number generator function which, given an integer number
n, generates a random number r, 0 < r < n. The algorithm has to be fast.
I tried to implement it using random_string:1:0:number, but the returned random
number sometimes always falls outside the range 0-n.
|Message posted by maybe Hubert Tonneau on 2002/07/24 14:19:14
|The following will work, provided you call it will 'n' not too big. If 'n' is
getting bigger the probability to get each value in the [0, n[ range is getting
function random n -> r
arg Int n r
memory_random addressof:(var uInt i) uInt:size
r := i%(cast n uInt)
|Message posted by maybe Marcus on 2002/07/24 14:29:02
I am currently developing an application (just for the fun of programming with
Pliant) which will help me teach math to my son, Tiago.
It's based on the idea of flash cards. A card representing a number n consists
of a white card with n red dots (2cm diameter) randomly arranged on the card.
I was supposed to make these cards by hand, using cardboard and pre-a-ply lables.
But I am too lazy for that...
|Message posted by maybe pom on 2002/07/26 05:45:29
|Pseudo random generators with good statistics are also available in
There are two of them implemented (ICG and EICG) and the source is fully documented.