Wracking my brain

BlitzMax Forums/BlitzMax Programming/Wracking my brain

Chroma(Posted 2006) [#1]
Anyone know how to call a simple function without using the parenthesis?

ie:


Print SomeNumber

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



GfK(Posted 2006) [#2]
You need to use parentheses if you're returning a value - no way around that.


Chroma(Posted 2006) [#3]
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?


GfK(Posted 2006) [#4]
You got me there.

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


Chroma(Posted 2006) [#5]
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)




VIP3R(Posted 2006) [#6]
a = Rand(0,50) + 50

?

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


H&K(Posted 2006) [#7]
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



Chroma(Posted 2006) [#8]
I'm shooting for it all on one line. ><


skidracer(Posted 2006) [#9]
Max(50,Rand(100))


H&K(Posted 2006) [#10]
a=50+rand(0,1)*Rand(50)


Edit: Well thats us told ;)


GfK(Posted 2006) [#11]
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


Floyd(Posted 2006) [#12]
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.


Chroma(Posted 2006) [#13]
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!


Chroma(Posted 2006) [#14]
Skidracer nailed it...but I know there's still a way to do it with > or &.

Do it in Blitz3D!


Floyd(Posted 2006) [#15]
Okay. Well, the 50+rand(0,1)*Rand(50) suggestion works in Blitz3D.


TomToad(Posted 2006) [#16]
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.


Chroma(Posted 2006) [#17]
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.


Smurftra(Posted 2006) [#18]
you could do

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

if what you want is one line.


TomToad(Posted 2006) [#19]
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?