GRASS 8 Programmer's Manual  8.5.0dev(2025)-c070206eb1
rand1.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <grass/gis.h>
3 #include <grass/gmath.h>
4 
5 /*!
6  * \fn float G_math_rand (int seed)
7  *
8  * \brief Random Number Generator (Uniform)
9  *
10  * Random number generator (Uniform Derivatives 0.0 -> 1.0)
11  *
12  * \param[in] seed
13  * \return float
14  */
15 float G_math_rand(void)
16 {
17  return G_drand48();
18 }
19 
20 /*!
21  * \brief Seed the pseudo-random number generator
22  *
23  * \param[in] seed 32-bit integer used to seed the PRNG
24  */
25 void G_math_srand(int seed)
26 {
27  G_srand48(seed);
28 }
29 
30 /*!
31  * \brief Seed the pseudo-random number generator from the time and PID
32  *
33  * \return generated seed value passed to G_srand48()
34  */
36 {
37  return (int)G_srand48_auto();
38 }
long G_srand48_auto(void)
Seed the pseudo-random number generator from the time and PID.
Definition: lrand48.c:70
double G_drand48(void)
Generate a floating-point value in the range [0,1)
Definition: lrand48.c:161
void G_srand48(long)
Seed the pseudo-random number generator.
Definition: lrand48.c:52
int G_math_srand_auto(void)
Seed the pseudo-random number generator from the time and PID.
Definition: rand1.c:35
void G_math_srand(int seed)
Seed the pseudo-random number generator.
Definition: rand1.c:25
float G_math_rand(void)
Definition: rand1.c:15