View previous topic :: View next topic |
Author |
Message |
DavidCbs
Joined: 02 Apr 2004 Posts: 17 Location: Suffolk, England
|
Posted: Wed Aug 04, 2004 1:42 pm Post subject: Random Number Generator component question |
|
|
Firstly, congratulations on the release of 1.1 . The enhancements and additions make Synopsis even easier to work with and offer yet more programming opportunities. I particularly like the icon graphics and the new implementation of the Service Call component.
My question regards the Set Seed service of the RNG component. Could you help me please by expanding on the use of this service. What does it achieve and in what situations is its use desirable or necessary?
As an example I am using two RNGs in a loop to produce a series of x and y coordinates that are then used to place graphics randomly within a defined area. I haven't used the Set Seed but the result seems to be alright.
Thanks in advance. _________________ DavidCbs |
|
Back to top |
|
|
CodeMorphis
Joined: 02 Dec 2003 Posts: 252
|
Posted: Thu Aug 05, 2004 8:15 pm Post subject: |
|
|
Thank you for your comments about Synopsis 1.1. The improvements made in Synopsis 1.1 are in great part due to the feedback that we received from users of Synopsis 1.0. We hope to continue to make improvements to the Synopsis product to deliver a continuously stronger visual programming and rapid prototyping tool. Please always feel free to post comments and suggestions as we use them to decide future feature sets and development projects.
For your question regarding the Random Number Generator component (from the Math tab of the Synopsis component tray), perhaps a little background information will help you out.
Any random number generator on a computer makes use of a mathematical algorithm to produce a sequence of numbers. In all cases, regardless of the machine or software involved, the name "random number generator" is in fact a slight misnomer. This is because a machine cannot give you true randomness - it needs some kind of formula to generate the sequence of numbers. If you knew what the formula was, you could compute and thus predict the numbers that would be generated. To help to "jumble" the numbers generated, we can make use of a seed number. This seed number defines a starting point for the number sequence generated.
To see how the seed number affects the sequence generated, consider the simple program below.
You can download this Synopsis 1.1 program here:
http://www.codemorphis.com/articles/Random_num_gen/Random_number_program.vpd
In our program we first call the "Set seed" service of the Random Number Generator component and then call the "Rand" service twice. The seed set in our program is 100. Note the output of the program in the console output area. We ran the program twice. For each run, the output is identical: the sequence of numbers generated is 65 followed by 16. This happens because we initialize the random number generator with the same seed number. If we were to use a different seed number for each run of the program, we could expect a different sequence of numbers.
In your program, you are not using the "Set seed" service. In fact, the random generator component is initialized with a default seed number. So yes your program will work but the numbers generated on each program run depend on the current state of the random generator component.
Often, programs will use some user interface method to allow the user to quietly (and unknowingly) specify a random number seed. For example, you could use the number of seconds that a system has been active or use the user's last mouse click coordinate. Thus, the seed number helps to prevent the case where on each run of your program, the sequence of random numbers is the same.
Hope that this explains things a little better. Please do not hesitate to ask more questions. |
|
Back to top |
|
|
DavidCbs
Joined: 02 Apr 2004 Posts: 17 Location: Suffolk, England
|
Posted: Mon Aug 09, 2004 9:43 am Post subject: RNG and seed |
|
|
Thanks for your help, I have a much better understanding now. I was not able to access your RNG demo programme via the link. Just got a page with one "t" on it. However I have used both seeded and seedless RNGs successfully in a small programme. _________________ DavidCbs |
|
Back to top |
|
|
CodeMorphis
Joined: 02 Dec 2003 Posts: 252
|
|
Back to top |
|
|
|