39 lines
799 B
C
39 lines
799 B
C
#pragma once
|
|
|
|
/**
|
|
* @def RNG(L,H)
|
|
*
|
|
* @brief Get a random number between L and H (L <= RNG <= H).
|
|
*
|
|
* If L is bigger than H it inverts the roles.
|
|
*/
|
|
#define RNG(L,H) (((L)>(H)) ? RNG_SANE((H), (L)) : RNG_SANE((L),(H)))
|
|
|
|
/**
|
|
* @def RNG_SANE(L,H)
|
|
*
|
|
* @brief Get a number between L and H (L <= RNG <= H).
|
|
*
|
|
* Result unspecified if L is bigger than H.
|
|
*/
|
|
#define RNG_SANE(L,H) ((int)L + (int)((double)(H-L+1) * randfp())) /* L <= RNG <= H */
|
|
|
|
/**
|
|
* @def RNGF()
|
|
*
|
|
* @brief Get a random float between 0 and 1 (0. <= RNGF <= 1.).
|
|
*/
|
|
#define RNGF() (randfp()) /* 0. <= RNGF <= 1. */
|
|
|
|
/* Init. */
|
|
void rng_init(void);
|
|
|
|
/* Random functions. */
|
|
unsigned int randint(void);
|
|
double randfp(void);
|
|
|
|
/* Probability functions. */
|
|
double Normal(double x);
|
|
double NormalInverse(double p);
|
|
|