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.

Dark GDK / Trouble with Random Numbers

Author
Message
EagleEye626
15
Years of Service
User Offline
Joined: 8th Sep 2009
Location:
Posted: 9th Sep 2009 03:25
Hi guys. Working on a C++ program in this class I'm taking. I'm having trouble with random numbers. I'm trying to get a circle drawn on the midpoint of a line. I think the problem is that my calculations aren't right because of the dbRND functions. How do you generate a random number between, say, 250 to 450?
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th Sep 2009 05:43 Edited at: 9th Sep 2009 05:43
dbRND returns a number between 0 and the number specified. If you want a range with a higher minimum, as in your example, determine the difference between the minimum and maximum and find a random value between 0 and that difference. Then add the minimum.

In your example, 450 - 250 = 200.

return 250 + dbRND (200);

I won't argue if dbRND is inclusive of zero or the expected maximum. A bit of experimentation should show if you need to increase the range by one or shift something down to get a zero base.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
EagleEye626
15
Years of Service
User Offline
Joined: 8th Sep 2009
Location:
Posted: 9th Sep 2009 06:12
That didn't work...what you said to do makes sense, but the circle keeps appearing in random places and not where it's supposed to.
EagleEye626
15
Years of Service
User Offline
Joined: 8th Sep 2009
Location:
Posted: 9th Sep 2009 06:15
Didn't work....it makes sense though, but the circle is still appearing in random places
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 9th Sep 2009 07:23
Quote: "That didn't work...what you said to do makes sense, but the circle keeps appearing in random places and not where it's supposed to.
"


Where is it supposed to? Random numbers shouldn't supposed to be in a supposed position.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
EagleEye626
15
Years of Service
User Offline
Joined: 8th Sep 2009
Location:
Posted: 9th Sep 2009 14:49
The line's endpoints are supposed to be random, and the circle is supposed to be on the midpoint of the line every time they are drawn.
puppyofkosh
17
Years of Service
User Offline
Joined: 9th Jan 2007
Location:
Posted: 9th Sep 2009 23:15
This should do it, but it doesn't use the darkGDK random functions

zapakitul
17
Years of Service
User Offline
Joined: 1st Mar 2007
Location: In my world
Posted: 10th Sep 2009 01:11 Edited at: 10th Sep 2009 01:11
This is what I use to generate random numbers:

Login to post a reply

Server time is: 2024-11-20 15:23:58
Your offset time is: 2024-11-20 15:23:58