Hunt for rand and srand implementations ;)

From: Skybuck Flying (nospam_at_hotmail.com)
Date: 10/28/04


Date: Thu, 28 Oct 2004 23:16:27 +0200

Hello,

This search for random implementations is starting to get interesting... so
time for a bit more professional approach ;)

If you know any implementations for srand() and rand() for a platform you
could add it to this (newsgroup) thread in this style:

Then we get a whole lot of srand and rand implementations =D

// visual c cpp 6 srand and rand
// implementation unknown...

void visual_c_cpp_6_srand( unsigned int seed )
{
 srand( seed );
}

int visual_c_cpp_6_rand(void)
{
 return rand();
}

// IBM AIX srand and rand implementation occurding to:
//
http://publib.boulder.ibm.com/infocenter/pseries/index.jsp?topic=/com.ibm.aix.doc/libs/basetrf2/rand.htm
static unsigned int IBM_AIX_next = 1;

int IBM_AIX_rand(void)
{
 IBM_AIX_next = IBM_AIX_next * 1103515245 + 12345;
 return ((IBM_AIX_next >>16) & 32767);
}

void IBM_AIX_srand(unsigned int Seed)
{
 IBM_AIX_next = Seed;
}

int main()
{
 int seed;

 // use same seed for all srand functions to find same implementations ;)
etc ;)
 seed = 12345;

 // visual c/c++ 6.0 srand and rand:
 printf("visual c/c++ 6.0 \n" );

 srand( seed );

 printf("rand1: %d \n", rand() );
 printf("rand2: %d \n", rand() );
 printf("rand3: %d \n", rand() );

 // visual c/c++ 6.0 rand output for srand seed 12345
 // rand1: 7584
 // rand2: 19164
 // rand3: 25795

 // IBM AIX srand and rand:
 printf("IBM AIX \n" );

 srand( seed );

 printf("rand1: %d \n", IBM_AIX_rand() );
 printf("rand2: %d \n", IBM_AIX_rand() );
 printf("rand3: %d \n", IBM_AIX_rand() );

 // IBM AIX rand output for srand seed 12345
 // rand1: 16838
 // rand2: 5758
 // rand3: 10113

 return 0;
}

Bye,
  Skybuck.



Relevant Pages

  • Re: Hunt for rand and srand implementations ;)
    ... Also I tested knoppix's rand and srand.... ... rand and srand... ... void srand(unsigned int seed); ... rand retrieves the pseudorandom numbers that are generated. ...
    (sci.crypt)
  • Re: Floating point load-store behaviour.
    ... This should be "int main". ... calling srand(), you're interfering with the generator. ... You should call srand() exactly once, ...
    (comp.lang.c)
  • Re: Hunt for rand and srand implementations ;)
    ... probably have the same srand() and randroutines... ... // IBM AIX srand and rand implementation occurding to: ... int IBM_AIX_rand ...
    (sci.crypt)
  • Re: rand and srand
    ... value from rand() by 2001, and returns the remainder - so the number can ... The C99 standard wants and int. ... automatic void of course with just as parameters. ... So is there really a need to use srand? ...
    (comp.lang.c)
  • Re: Random string
    ... The time between a call to srand() and a subsequent ... call to rand() makes no difference whatsoever unless 1) your ... int rand_lim{ ...
    (microsoft.public.vc.mfc)