Random number generation

Hi, folks!

I need to generate some random real values. I know that FreeFEM is equipped with the functions randreal1, randreal2, randreal3, randres53, for generating random real numbers between 0 and 1.

[1] Please, try to run the following code several times.

for(int i = 0; i < 3; i++){
cout << " ranx = " << randreal3() << endl; 
cout << " \n " << endl; 
}

It seems there is a pattern when generating the random values. In particular, the numbers appearing on the first run of code are the same as those appearing in the next executions of the code. This is something that shouldn’t happen, isn’t it?

Remark: I have read some insights for solving this issue. It seems I should start the code with randinit(100*clock()); However, if 100*clock() is almost the same for multiple code runs, then the values obtained from randreal3() are also the same, i.e., it does not return random values.

[2] Suppose I need to generate random numbers between 1 and 2. Is there a routine for this task?

Thanks in advance,
Lucas.

Here is a solution by Professor Frédéric Hecht:

The problem is classique see

do:

load "ffrandom"
srandomdev(); // set a true ramdom seed ..