Wracking my brain

BlitzMax Forums/BlitzMax Programming/Wracking my brain

Anyone know how to call a simple function without using the parenthesis?

ie:


Print SomeNumber

Function SomeNumber:Int()
     Return Rand(1,500)
End Function


You need to use parentheses if you're returning a value - no way around that.

Hmm...another simple one...say i have a random number and i want it to have a minimum

a = rand(1,100) > 50

a = rand(1,100) & 50



I forget how to make the number roll from 1 to 100 but if it's below 50 then set it to 50. The shor short way...not the if a < 50 then a=50 stuff. Anyone remember how?

You got me there.

Any reason why Rand(50,100) is unsuitable?

If I do a Rand(50,100) then the number will most definitely fall between those 2 numbers. If I do a Rand(1,100) and limit the result to 50 through 100 then 50 will come up 50% of the time...which is what I'm aiming for.

A simple If statement would work. But it's like when you can't remember the name to a movie or book you saw or read many years ago and it's bugging me. I'm googling it. If you find it before I do...

this = rand(1,100)
if this < 50 then this = 50

'or

this = rand(1,100) > 50 & blah blah (can't remember)



a = Rand(0,50) + 50

?

[edit] Nevermind, after reading your post above I can see that's not what you want.

Gfk that would hardly ever give 50, when the anwser should be 50 one half the time

If Rnd ()>=0.5
a = 50
else
a=Rand(51,100)
endif
A=rand (1,100)
If a<= 50 then a=50


I'm shooting for it all on one line. ><

Max(50,Rand(100))

a=50+rand(0,1)*Rand(50)


Edit: Well thats us told ;)

Max(50,Rand(100))
Heh, just looked at that and couldn't figure out how to use it.

In my defence, its nearly 5am. :s

Am I the only one who suspects we still don't know the real question?

It sounds like he wants to choose a number from {50,51,52,... 100} with 50 occurring 50% of the time and all other numbers 1%.

But I can't think of a reason to want such a thing.

Floyd...you can talk directly to me, i don't bite. =p

The number selected may be from 1 to 100. But...if the number is 49 or below then the number returned will be 50. But I know there's a way to use the > or & symbol to do it instead of using IF...THEN.

It's just a matter of doing it all on one line.

It's kinda like doing a stunt on your dirtbike and impressing the ladies!

Skidracer nailed it...but I know there's still a way to do it with > or &.

Do it in Blitz3D!

Okay. Well, the 50+rand(0,1)*Rand(50) suggestion works in Blitz3D.

The number selected may be from 1 to 100. But...if the number is 49 or below then the number returned will be 50. But I know there's a way to use the > or & symbol to do it instead of using IF...THEN.

I think you're confusing it with C and C++ in which
if (a=Rand(1,100)<50) a=50;

is valid C code.

Nah, I've seen someone do it in Blitz3D...I just can't remember how it was done.

Or...what I saw in Blitz3D might not be the same as what I'm trying to do...that's the sad part, I can't remember.

you could do

Rand(2)*Rand(1,50) + 50

if what you want is one line.

Now I have done
If Rand(1,4) > 1 then DoSomething()
to make sure that DoSomething is called 75% of the time. Is this perhaps what you've seen?