Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
167 user(s) are online (124 user(s) are browsing Forums)

Members: 1
Guests: 166

orgin, more...

Headlines

 
  Register To Post  

Rand()
Home away from home
Home away from home


See User information
I'm using rand() to get a random number each time i want one. But on startup it gives the exact same number each time, giving me exact the same song each time i start it. Which i don't want. Why call it rand then?? Other solutions?

X5000
Go to top
Re: Rand()
Just can't stay away
Just can't stay away


See User information
@Antique

Like with any other pseudo random number generator before using rand() you need to seed it using the srand() function.

A common, portable way to seed it is to use the output of time(NULL):
srand(time(NULL));

If you seed it using the same value you will get the same sequence of numbers from it (this can have it's uses).

If you want really random numbers at cost of portability you can also use the RANDOM: device of AmigaOS (just open it as a file and read from it) or alternately you can use the entropy unit of timer.device directly as I do in my mkpasswd program (source code included).

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project