rand, srand not implemented ?!

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi, it's true ?

I'm trying to add this function but as an external .s

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here is the pretty much universal standard for rand() and srand():

#define RAND_MAX 32767

static unsigned long seed = 1;

int rand(void)
{
seed = seed * 1103515245 + 12345;
return (int)(seed / 65536) % (((int)RAND_MAX) + 1);
}

void srand(unsigned long newSeed)
{
seed = newSeed;
}

This comes, more or less, from the ANSI C example.

Jim

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Upon further inspection, it looks rand() and srand() are implemented, at least in the latest version of the library (I haven't checked the older libraries). They are located in the header stdlib.h.

Jim