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.

DarkBASIC Professional Discussion / How to get a random DECIMAL value??

Author
Message
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 6th Jun 2010 23:10
Today I tried to get a random value between 0.00 and 0.99, and it doesn't seem to work. The command rnd() returns integer values, I know, but when I divide that value by 100, it doesn't work. This is the code that I've tried:



So, does anyone know why this doesn't work or how to make it work?

Thanks in advance.

Cheers

Slayer rules!!! Yeaaah, man!
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 6th Jun 2010 23:28
the operators you're using are still dealing with integers thar.

if you say:
c#=15/10, then c# will be 1, because 15/10 using integer division gives an integer result, 1. saying rnd(9)/10 will always be preforming integer division. Solution? replace "C1# = C/10" with "C1# = C/10.0"
10 is an integer, but 10.0 is a float, and you need a float.


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
HowDo
23
Years of Service
User Offline
Joined: 28th Nov 2002
Location: United Kingdom
Posted: 6th Jun 2010 23:33
try this, one of your value need a decimal in it to work.



Dark Physics makes any hot drink go cold.
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 6th Jun 2010 23:43
Thanks guys, that worked!
I thought that just adding the # would do the trick. I was a little confused because I work a lot in Excel lately, and I assumed that dividing by 100 was enough.

Cheers

Slayer rules!!! Yeaaah, man!
KISTech
18
Years of Service
User Offline
Joined: 8th Feb 2008
Location: Aloha, Oregon
Posted: 7th Jun 2010 01:14
c = rnd(99)
t$ = "0." + str$(c)
t = val(t$)
print t

Digger412
19
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 7th Jun 2010 05:38
@KISTech - You beat me to it x.x
BatVink
Moderator
23
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jun 2010 14:54
don't forget to start with something along the lines of RANDOMIZE TIMER() or you'll get the same random values every time.

Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 7th Jun 2010 18:51 Edited at: 7th Jun 2010 19:20
Just an idea:


And with precision:


A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.

Login to post a reply

Server time is: 2026-07-25 16:21:10
Your offset time is: 2026-07-25 16:21:10