Loading...
Searching...
No Matches
lrand48.c File Reference

GIS Library - Pseudo-random number generation. More...

`#include <stdio.h>`
`#include <stdlib.h>`
`#include <string.h>`
`#include <errno.h>`
`#include <grass/gis.h>`
`#include <grass/glocale.h>`
`#include <time.h>`
`#include <sys/types.h>`
`#include <unistd.h>`
Include dependency graph for lrand48.c:

Go to the source code of this file.

## Macros

#define | LO(x)
#define | HI(x)

## Typedefs

typedef unsigned short | uint16
typedef unsigned int | uint32
typedef signed int | int32

## Functions

void | G_srand48 (long seedval)
| Seed the pseudo-random number generator.
long | G_srand48_auto (void)
| Seed the pseudo-random number generator from the time and PID.
long | G_lrand48 (void)
| Generate an integer in the range [0, 2^31).
long | G_mrand48 (void)
| Generate an integer in the range [-2^31, 2^31).
double | G_drand48 (void)
| Generate a floating-point value in the range [0,1).

## Detailed Description

GIS Library - Pseudo-random number generation.

(C) 2014 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
  Glynn Clements

Definition in file lrand48.c.

## Macro Definition Documentation

## HI

#define HI | ( |  | x | ) |

Value:
((x) >> 16)
x
#define x

Definition at line 45 of file lrand48.c.

Referenced by G_srand48().

## LO

#define LO | ( |  | x | ) |

Value:
((x) & 0xFFFFU)

Definition at line 44 of file lrand48.c.

Referenced by G_srand48().

## Typedef Documentation

## int32

typedef signed int int32

Definition at line 33 of file lrand48.c.

## uint16

typedef unsigned short uint16

Definition at line 31 of file lrand48.c.

## uint32

typedef unsigned int uint32

Definition at line 32 of file lrand48.c.

## Function Documentation

## G_drand48()

double G_drand48 | ( | void |  | ) |

Generate a floating-point value in the range [0,1).

Returns
  the generated value

Definition at line 161 of file lrand48.c.

References r.

Referenced by f_rand(), and G_math_rand().

## G_lrand48()

long G_lrand48 | ( | void |  | ) |

Generate an integer in the range [0, 2^31).

Returns
  the generated value

Definition at line 133 of file lrand48.c.

References r.

## G_mrand48()

long G_mrand48 | ( | void |  | ) |

Generate an integer in the range [-2^31, 2^31).

Returns
  the generated value

Definition at line 147 of file lrand48.c.

References r.

Referenced by f_rand().

## G_srand48()

void G_srand48 | ( | long | seedval | ) |

Seed the pseudo-random number generator.

Parameters

  [in] | seedval | 32-bit integer used to seed the PRNG

Definition at line 52 of file lrand48.c.

References HI, LO, and x.

Referenced by G_math_srand(), and G_srand48_auto().

## G_srand48_auto()

long G_srand48_auto | ( | void |  | ) |

Seed the pseudo-random number generator from the time and PID.

A weak hash of the current time and PID is generated and used to seed the PRNG

Returns
  generated seed value passed to G_srand48()

Definition at line 70 of file lrand48.c.

References G_fatal_error(), G_srand48(), NULL, and t.

Referenced by G_math_srand_auto().