GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
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 
16 float G_math_rand(void)
17 {
18  return G_drand48();
19 }
20 
21 /*!
22  * \brief Seed the pseudo-random number generator
23  *
24  * \param seedval 32-bit integer used to seed the PRNG
25  */
26 
27 void G_math_srand(int seed)
28 {
29  G_srand48(seed);
30 }
31 
32 /*!
33  * \brief Seed the pseudo-random number generator from the time and PID
34  *
35  * \return generated seed value passed to G_srand48()
36  */
37 
39 {
40  return (int)G_srand48_auto();
41 }
long G_srand48_auto(void)
Seed the pseudo-random number generator from the time and PID.
Definition: lrand48.c:72
double G_drand48(void)
Generate a floating-point value in the range [0,1)
Definition: lrand48.c:166
void G_srand48(long)
Seed the pseudo-random number generator.
Definition: lrand48.c:53
int G_math_srand_auto(void)
Seed the pseudo-random number generator from the time and PID.
Definition: rand1.c:38
void G_math_srand(int seed)
Seed the pseudo-random number generator.
Definition: rand1.c:27
float G_math_rand(void)
Definition: rand1.c:16