# PETSc - how computing a random number between 0 and 1?

In PETSc, I need to generate a random number between 1 and 0.

With the include cstdlib, the classical trick is:

(double)rand() / (double)RAND_MAX


In PETSc, the constant RAND_MAX does not seem to exist.

Is there a work around?

Though it is ugly, I plan to do something similar to:

(rand() % 10000) / 10000.0

• You may want to use another library, like SPRNG – Paul Mar 18 '16 at 19:17