Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Logic Problem, or is random not that random? Can anyone help

Author
Message
Colin Hart
21
Years of Service
User Offline
Joined: 28th Apr 2003
Location: United Kingdom
Posted: 12th Jun 2005 02:44
Afternoon almost evening all.

I have written some sample code to work on my logic before inmplimeting the code into the main program. The basic run down is.

The procedure is called, it generates a random number between 2800, this is the total number of pixals round the out side of a 800 X 600 screen.

This number is trasformed into x and y positions. The problem I having is the same answers keep appearing.. I have used the strep through function in "debug" mode with no joy. The programruns, just doesn't do quite what I expect.

Can anyone shed any light on the matter. I have pasted my code in. The sub routine that does the caculation is called "_piestart:"

Thank you very much for reading.

Colin.
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 12th Jun 2005 02:48
add randomize timer() at the start of your code

If no-one gives your an answer to a question you have asked, consider:- Is your question clear.- Did you ask nicely.- Are you showing any effort to solve the problem yourself 
BF game programmer
19
Years of Service
User Offline
Joined: 22nd Jan 2005
Location: hoover alabama
Posted: 12th Jun 2005 02:56 Edited at: 12th Jun 2005 02:56
he answered the question!

james bond rules and star wars
Kevin Picone
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 12th Jun 2005 03:01 Edited at: 12th Jun 2005 03:05
In order to make random numbers 'appear' random, you need to seed the random number generator by using the Randomize command.

This command initializes the internal random number generator, so that subsequence polls of the RND() function, will return values from this particular seeded sequence. So setting a particular seed, will generate the same sequence, time in, time out. This can useful when you need it, but annoying when you don't . An good example of this being a useful feature, would be using fractals to generate terrains/texture maps. As when seeded with the same random sequence, you'll get the same terrain every time.

Anyway, In order to make it appear random, you need to Seed the generator with some value from the computer that is constantly changing, so it won't be the same each time the program code is compiled & executed. For this, we use the TIMER() function. The Timer() function returns the current millisecond, taken from when the computer was last started. There are 1000 milliseconds per second, so this valid is changing rapidly, making it perfect way to seed our random number generator.

So long story short, by adding this line of code 'Randomize Timer()' to the start of your code, will ensure that the random sequence is different each time.

Kevin Picone
[url]www.underwaredesign.com[/url]
Play Nice! Play Basic (Release V1.073 Out Now)
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 12th Jun 2005 03:16
thanks uw

If no-one gives your an answer to a question you have asked, consider:- Is your question clear.- Did you ask nicely.- Are you showing any effort to solve the problem yourself 
Colin Hart
21
Years of Service
User Offline
Joined: 28th Apr 2003
Location: United Kingdom
Posted: 12th Jun 2005 03:45
This answers one question thank you very much. However I still can not seem to get the "pie" to move intothe screen correctly. The X Y cordinates show one thing yet the image comes in usualy at 0,20 ish.

Can any one help?

Thak you a for the advices earlier, very usful information.

Kind Regards

Colin

P.S new code attached.

Login to post a reply

Server time is: 2024-09-23 21:25:07
Your offset time is: 2024-09-23 21:25:07