update name of code to labcodes
This commit is contained in:
26
labcodes/lab3/libs/rand.c
Normal file
26
labcodes/lab3/libs/rand.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <x86.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static unsigned long long next = 1;
|
||||
|
||||
/* *
|
||||
* rand - returns a pseudo-random integer
|
||||
*
|
||||
* The rand() function return a value in the range [0, RAND_MAX].
|
||||
* */
|
||||
int
|
||||
rand(void) {
|
||||
next = (next * 0x5DEECE66DLL + 0xBLL) & ((1LL << 48) - 1);
|
||||
unsigned long long result = (next >> 12);
|
||||
return (int)do_div(result, RAND_MAX + 1);
|
||||
}
|
||||
|
||||
/* *
|
||||
* srand - seed the random number generator with the given number
|
||||
* @seed: the required seed number
|
||||
* */
|
||||
void
|
||||
srand(unsigned int seed) {
|
||||
next = seed;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user