Random generator?

kurris
kurris used Ask the Experts™
on
I have these lines:

x = rnd(0, max);
y = rnd(0, max);

max is 99 right now, but could, of course, be changed to
whatever I need at the moment.

What I would like is for someone to make me the rnd function.
It should generate different numbers every time, or at least
as often as possible.

So what I really need is a function that can generate a random
number between 0 and max.

I hope you can help me!

Regards,

Kristoffer Larsson
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Adjusted points to 150

Commented:
increase the points and I can write you one.
Commented:
//Use the randomize() with rand() Function


#include <stdlib.h>
#include <stdio.h>
#include <time.h>

int main(void)
{
    int i;

    randomize();
    printf("Ten random numbers\n\n");
    for(i=0; i<10; i++)
        printf("%d\n", rand() % 150); //change the 150
    return 0;
}

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial