Random # generation-seeding...what is it?

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0
What does it mean to seed a random number??

(im teaching myself Java...out of just about no previous programming experience)

Anyway, the book (Java in a Nutshell) talks about seeding...and I have no idea as to what that is...

if someone could explain, it'd b much appreciated.

thanks,
-eric
 

markjrubin

Golden Member
Jan 17, 2000
1,419
0
0
Eric,

Can you use it in a sentence? Seeding data normally means something like this

You've got a program that you want to test and you want to see how well it performs with random data. You write a random seed generator to dynamically create sample data for your program. You then run your program and analyze the results.

If you tell us what you want, I can give you some sample code.
 

CodeJockey

Member
May 1, 2001
177
0
0
Eric,

This might be more helpful to you...

A random number generator is normally a function or class that does just what it sounds like, generates random numbers (actually, they are pseudo-random, meaning that the seed determines the series of numbers you will get. With the same seed, you will always get the same series of numbers.)

Most functions pick a specific value like zero to use for the seed, until it is changed by the user (you, the programmer using the function). This is handy for testing, since each time you run your program, the same sequence will be generated, and if you find a bug, you can fix it, run again, and confirm that it is gone. It isn't so good for actual use though (for example in a card game, since each time you shuffle the cards it will do so using the same random numbers, and the deck will end up being in the same order as the last run).

Therefore, you need to seed the random number generator function you use with a truly random value (the current time is usually used), in order to make the numbers generated by the function different each time you run the program.

There is usually a function or method that will let you specify the seed.
 

eLiu

Diamond Member
Jun 4, 2001
6,407
1
0
ooohhhhh!!

thanks codejockey :)

so...the seed kind of "sets" the random # generator, right?

that's the explanation i wuz lookin for... :)

-eric