SDL_test_random.c File Reference
`#include "SDL_config.h"`
`#include <stdlib.h>`
`#include <stdio.h>`
`#include <time.h>`
`#include "SDL_test.h"`
Include dependency graph for SDL_test_random.c:

Go to the source code of this file.

## Functions

void | SDLTest_RandomInit (SDLTest_RandomContext *rndContext, unsigned int xi, unsigned int ci)
| Initialize random number generator with two integers. More...
void | SDLTest_RandomInitTime (SDLTest_RandomContext *rndContext)
| Initialize random number generator based on current system time. More...
unsigned int | SDLTest_Random (SDLTest_RandomContext *rndContext)
| Initialize random number generator based on current system time. More...

## Function Documentation

## SDLTest_Random()

unsigned int SDLTest_Random | ( | SDLTest_RandomContext * | rndContext | ) |

Initialize random number generator based on current system time.

Note: ...RandomInit() or ...RandomInitTime() must have been called before using this function.

Parameters

  rndContext | pointer to context structure

Returns
  A random number (32bit unsigned integer)

Definition at line 80 of file SDL_test_random.c.

References SDLTest_RandomContext::a, SDLTest_RandomContext::ah, SDLTest_RandomContext::al, SDLTest_RandomContext::c, NULL, and SDLTest_RandomContext::x.

Referenced by SDLTest_GenerateRunSeed().

{
unsigned int xh, xl;
if (rndContext==NULL) return -1;
xh = rndContext->x >> 16, xl = rndContext->x & 65535;
rndContext->x = rndContext->x * rndContext->a + rndContext->c;
rndContext->c =
xh * rndContext->ah + ((xh * rndContext->al) >> 16) +
((xl * rndContext->ah) >> 16);
if (xl * rndContext->al >= (~rndContext->c + 1))
rndContext->c++;
return (rndContext->x);
}
SDLTest_RandomContext::a
unsigned int a
Definition: SDL_test_random.h:60
SDLTest_RandomContext::ah
unsigned int ah
Definition: SDL_test_random.h:63
SDLTest_RandomContext::c
unsigned int c
Definition: SDL_test_random.h:62
SDLTest_RandomContext::x
unsigned int x
Definition: SDL_test_random.h:61
NULL
#define NULL
Definition: begin_code.h:164
SDLTest_RandomContext::al
unsigned int al
Definition: SDL_test_random.h:64

## SDLTest_RandomInit()

void SDLTest_RandomInit | ( | SDLTest_RandomContext * | rndContext,
|  | unsigned int | xi,
|  | unsigned int | ci
| ) |  |

Initialize random number generator with two integers.

Note: The random sequence of numbers returned by ...Random() is the same for the same two integers and has a period of 2^31.

Parameters

  rndContext | pointer to context structure
  xi | integer that defines the random sequence
  ci | integer that defines the random sequence

Definition at line 41 of file SDL_test_random.c.

References SDLTest_RandomContext::a, SDLTest_RandomContext::ah, SDLTest_RandomContext::al, SDLTest_RandomContext::c, NULL, and SDLTest_RandomContext::x.

Referenced by main(), SDLTest_FuzzerInit(), and SDLTest_RandomInitTime().

{
if (rndContext==NULL) return;
/*
* Choose a value for 'a' from this list
* 1791398085 1929682203 1683268614 1965537969 1675393560
* 1967773755 1517746329 1447497129 1655692410 1606218150
* 2051013963 1075433238 1557985959 1781943330 1893513180
* 1631296680 2131995753 2083801278 1873196400 1554115554
*/
rndContext->a = 1655692410;
rndContext->x = 30903;
rndContext->c = 0;
if (xi != 0) {
rndContext->x = xi;
}
rndContext->c = ci;
rndContext->ah = rndContext->a >> 16;
rndContext->al = rndContext->a & 65535;
}
SDLTest_RandomContext::a
unsigned int a
Definition: SDL_test_random.h:60
SDLTest_RandomContext::ah
unsigned int ah
Definition: SDL_test_random.h:63
SDLTest_RandomContext::c
unsigned int c
Definition: SDL_test_random.h:62
SDLTest_RandomContext::x
unsigned int x
Definition: SDL_test_random.h:61
NULL
#define NULL
Definition: begin_code.h:164
SDLTest_RandomContext::al
unsigned int al
Definition: SDL_test_random.h:64

## SDLTest_RandomInitTime()

void SDLTest_RandomInitTime | ( | SDLTest_RandomContext * | rndContext | ) |

Initialize random number generator based on current system time.

Parameters

  rndContext | pointer to context structure

Definition at line 65 of file SDL_test_random.c.

References NULL, and SDLTest_RandomInit().

Referenced by main(), and SDLTest_GenerateRunSeed().

{
int a, b;
if (rndContext==NULL) return;
srand((unsigned int)time(NULL));
a=rand();
srand((unsigned int)clock());
b=rand();
SDLTest_RandomInit(rndContext, a, b);
}
time
EGLSurface EGLnsecsANDROID time
Definition: eglext.h:518
SDLTest_RandomInit
void SDLTest_RandomInit(SDLTest_RandomContext *rndContext, unsigned int xi, unsigned int ci)
Initialize random number generator with two integers.
Definition: SDL_test_random.c:41
NULL
#define NULL
Definition: begin_code.h:164
a
GLboolean GLboolean GLboolean GLboolean a
Definition: SDL_opengl_glext.h:1109
b
GLboolean GLboolean GLboolean b
Definition: SDL_opengl_glext.h:1109