5.1. Example rand implementation
// example of small rand implementation
//
#include <stdio.h>
int my_seed = 0;
void my_srand( int s) // set my_seed
{
my_seed = s;
}
int my_rand( void) // update and return my_seed
{
my_seed = (137 * my_seed + 187) % 256;
return my_seed;
}
int main( void)
{
int i;
for( i = 1; i < 300; ++i)
{
printf( "%5i", my_rand());
if( i % 15 == 0) putchar( '\n'); // print 15 values per line
}
putchar( '\n');
return 0;
}