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 / Generation of a random REAL number?

Author
Message
Monzi
20
Years of Service
User Offline
Joined: 10th May 2004
Location: Denmark
Posted: 7th Jan 2005 02:14
How do i generate a random REAL number...
I tried this:

Speed#=Rnd(1.0)+1.0

But it only returns 1 and 2.

How do i do it?

Tiny Kitten Software -
http://monz.adsl.dk/tks/
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 7th Jan 2005 02:17 Edited at: 7th Jan 2005 02:18
You could do this:



To get a random real between 0 and 67?



Think that works To get different numbers of decimal places change the 10,000.

Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"
Monzi
20
Years of Service
User Offline
Joined: 10th May 2004
Location: Denmark
Posted: 7th Jan 2005 02:30
Thanks for the inspiration

But i cooked it down to one line:
Speed#=1.0/(RND(9.0)+1.0)+RND(1.0)

This Generates a random number between 1.0 and 2.0 which is what i needed for my game

Tiny Kitten Software -
http://monz.adsl.dk/tks/
Mnemonix
21
Years of Service
User Offline
Joined: 2nd Dec 2002
Location: Skaro
Posted: 7th Jan 2005 02:48
Putting complex equations within a single statement is generally a bad idea. Its known as cryptic programming and makes your code harder to read. Besides, there is no way to make a real random number because of the way computers work.

The 3d chat is coming...
Rights For Traffic Cones!
Monzi
20
Years of Service
User Offline
Joined: 10th May 2004
Location: Denmark
Posted: 7th Jan 2005 03:07
I know its not possible to make real random numbers on a computer. Nothing new there. But when i said REAL numbers i meant a number with decimals, 1.2 or 6.95 for example.

And i dont agree with you on the "complex equations" issue. I find it much more easy to read my code if an equation is fitted into one line instead of 10 lines. It makes it easier to navigate around the code if it can fill 100 lines instead of 500 lines.

What i do to make it easier to understand is to put in a few REM remarks instead.

And by the way, this code isnt really complex. Its perfectly straight forward.

Tiny Kitten Software -
http://monz.adsl.dk/tks/
David T
Retired Moderator
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: England
Posted: 7th Jan 2005 05:35
I like to make equations as similar to their prototypes as possible, ie:

speed = distance / time

I'd probably write:



Get 15 new commands, all the date / time commands left out of DBPro for free!
DOWNLOAD PLUGINS HERE: http://www.davidtattersall.me.uk/ and select "DarkBasic"
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 7th Jan 2005 05:41 Edited at: 7th Jan 2005 05:42
I have a random number generator posted in the codebase (not really random as Mnem just had to point out )

http://www.thegamecreators.com/?m=codebase_view_code&i=ec03b2ee8108c389ddf7072e24f770c3

You can use it to generate ranges easily, such as from 1.0 to 2.0:

x# = FloatRndRange(1.0, 2.0)

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 8th Jan 2005 05:24
speed#=(10+rnd(10))/100

Login to post a reply

Server time is: 2024-11-11 22:35:16
Your offset time is: 2024-11-11 22:35:16