Rand returning Int

BlitzMax Forums/BlitzMax Programming/Rand returning Int

I was using SuperStrict and have a long variable that I want a random number for if I use Rand I get an error IntToLong error or summat like that, is there way to make it return a long number.

Does max do casting?

long(rand(n,n+1))?

You get an error with what code?

I can do this :-

Global i:Long = Rand(0,100)

with no problems.

Explicit casting is performed by this kind of syntax (brackets are unneccessary but I always use them)

Global x:Int
Global y:Float

y = 10.0
x = Int(y) ' Here's the cast to Int

Not quite what you asked for, but it fakes it well enough:
SuperStrict

SeedRnd(MilliSecs())

Local random:Long = Rand(0,$7fffffff)
random :Shl 32
random :| Rand(0,$7fffffff)
Print random
Print LongHex (random)
I'm sure you could elaborate on it to cover the last two missing bits if you really need them bad enough.

Then simply use -$8000000 as the minimum value rather than 0. You'll get *all* your bits randomly filled.

I had a Long in a type and the compiler was throwing an error on the Rand, when I remarked the line out it compiled fine it also ran perfectly when I changed it to Rnd too. This is why I asked. I will try the method's you describe thanks :)