Decimal problem

BlitzMax Forums/BlitzMax Beginners Area/Decimal problem

Eren(Posted 2015) [#1]
I'm trying to create a random number with a decimal, which will be held within a float variable. But whenever I generate the number, the decimal is always '.0'. How can I get a value that has a value AND a decimal value of not just 0?


Zethrax(Posted 2015) [#2]
Firstly, when you ask questions like this make sure you post some code or take the time to properly explain the situation you're encountering the problem in.

In this case BlitzMax has several functions for generating random numbers. Knowing which one you're using would go a long way to aid people in answering your question.

The code below all seems to work fine.
' Seed the random number generator from the millisecond timer so we don't get the same range of numbers each time.
SeedRnd MilliSecs()

myvar1:Double = Rnd( 10.0, 20.0 ) ' Rnd generates a random double in the range min (inclusive) to max (exclusive)
myvar2:Float = Rnd( 10.0, 20.0 ) ' Can be stored in a float.
myvar3:Float = RndFloat() * 10.0 + 10 ' RndFloat generates a float in the range 0.0 to 1.0 (0 (inclusive) to 1 (exclusive) ). Multiply it by whatever you want your value range to be.
myvar4:Float = RndDouble() * 10.0 + 10 ' RndDouble generates a double in the range 0.0 to 1.0 (0 (inclusive) to 1 (exclusive) ). Multiply it by whatever you want your value range to be.
myint:Int = Rand( 10, 20 ) ' Rand generates a random integer in the range min (inclusive) to max (inclusive) 

Print myvar1
Print myvar2
Print myvar3
Print myvar4
Print myint

End