Back to index

libdrm  2.4.37
Classes | Defines | Typedefs | Functions
xf86drmRandom.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "xf86drm.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  RandomState

Defines

#define RANDOM_MAIN   0
#define RANDOM_MAGIC   0xfeedbeef
#define RANDOM_DEBUG   0
#define RANDOM_ALLOC   drmMalloc
#define RANDOM_FREE   drmFree

Typedefs

typedef struct RandomState RandomState

Functions

void * drmRandomCreate (unsigned long seed)
int drmRandomDestroy (void *state)
unsigned long drmRandom (void *state)
double drmRandomDouble (void *state)

Class Documentation

struct RandomState

Definition at line 94 of file xf86drmRandom.c.

Class Members
unsigned long a
unsigned long check
unsigned long m
unsigned long magic
unsigned long q
unsigned long r
long seed

Define Documentation

#define RANDOM_ALLOC   drmMalloc

Definition at line 90 of file xf86drmRandom.c.

#define RANDOM_DEBUG   0

Definition at line 84 of file xf86drmRandom.c.

#define RANDOM_FREE   drmFree

Definition at line 91 of file xf86drmRandom.c.

#define RANDOM_MAGIC   0xfeedbeef

Definition at line 83 of file xf86drmRandom.c.

#define RANDOM_MAIN   0

Definition at line 77 of file xf86drmRandom.c.


Typedef Documentation

typedef struct RandomState RandomState

Function Documentation

unsigned long drmRandom ( void *  state)

Definition at line 147 of file xf86drmRandom.c.

{
    RandomState   *s = (RandomState *)state;
    long          hi;
    long          lo;

    hi      = s->seed / s->q;
    lo      = s->seed % s->q;
    s->seed = s->a * lo - s->r * hi;
    if (s->seed <= 0) s->seed += s->m;

    return s->seed;
}

Here is the caller graph for this function:

void* drmRandomCreate ( unsigned long  seed)

Definition at line 111 of file xf86drmRandom.c.

{
    RandomState  *state;

    state           = RANDOM_ALLOC(sizeof(*state));
    if (!state) return NULL;
    state->magic    = RANDOM_MAGIC;
#if 0
                            /* Park & Miller, October 1988 */
    state->a        = 16807;
    state->m        = 2147483647;
    state->check    = 1043618065; /* After 10000 iterations */
#else
                            /* Park, Miller, and Stockmeyer, July 1993 */
    state->a        = 48271;
    state->m        = 2147483647;
    state->check    = 399268537; /* After 10000 iterations */
#endif
    state->q        = state->m / state->a;
    state->r        = state->m % state->a;

    state->seed     = seed;
                            /* Check for illegal boundary conditions,
                                   and choose closest legal value. */
    if (state->seed <= 0)        state->seed = 1;
    if (state->seed >= state->m) state->seed = state->m - 1;

    return state;
}
int drmRandomDestroy ( void *  state)

Definition at line 141 of file xf86drmRandom.c.

{
    RANDOM_FREE(state);
    return 0;
}
double drmRandomDouble ( void *  state)

Definition at line 161 of file xf86drmRandom.c.

{
    RandomState *s = (RandomState *)state;
    
    return (double)drmRandom(state)/(double)s->m;
}

Here is the call graph for this function: