Xyris  0.5
rand.cpp File Reference
#include <Library/rand.hpp>
+ Include dependency graph for rand.cpp:

Go to the source code of this file.

Functions

int rand (void)
 
void srand (unsigned int seed)
 

Variables

unsigned long _seedrand = 1
 

Detailed Description

Portable implementation of rand and srand as according to the C standard implementation by K&R.

Author
Brian Kernighan, Dennis Ritchie (C Standard Authors)
Michel (JMallone) Gomes (miche.nosp@m.ls@u.nosp@m.tfpr..nosp@m.edu..nosp@m.br)
Version
0.1
Date
2021-07-20

References: https://wiki.osdev.org/Random_Number_Generator#The_Standard.27s_Example https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html

Definition in file rand.cpp.

Function Documentation

◆ rand()

int rand ( void  )

Return a random value.

Returns
int Value from random number generator

Definition at line 22 of file rand.cpp.

23 {
24  _seedrand = _seedrand * 214013L + 2531011L;
25  return (unsigned int)(_seedrand >> 16) & MAX_RAND;
26 }

◆ srand()

void srand ( unsigned int  seed)

Set a seed to rand.

Parameters
seedRandom number generator seed

Definition at line 28 of file rand.cpp.

29 {
30  _seedrand = seed;
31 }

Variable Documentation

◆ _seedrand

unsigned long _seedrand = 1

Definition at line 20 of file rand.cpp.

_seedrand
unsigned long _seedrand
Definition: rand.cpp:20
MAX_RAND
#define MAX_RAND
Definition: rand.hpp:18