Page 1 of 2
[Implemented] Random
Posted: Fri May 20, 2005 8:05 pm
by Polo
I've made the request before, but could the function Random have two parameters ? I just don't see why values should specificaly start from 0, we need the ability to choose the start value

Posted: Fri May 20, 2005 9:19 pm
by Fred
What about this: Random(10)+StartValue.
May be it should be written in the doc

Posted: Fri May 20, 2005 9:23 pm
by Joakim Christiansen
It will now start at 5 and end at 20...
Posted: Fri May 20, 2005 9:25 pm
by Gansta93
Why don't you want to add it?
Posted: Fri May 20, 2005 10:32 pm
by Fred
It's just useless.
Posted: Fri May 20, 2005 10:48 pm
by Polo
Far from useless.
It makes the command a little bit more advanced without too much work...
It's good to have workaround, but too much workaround kill easy programmation

Posted: Fri May 20, 2005 11:37 pm
by nco2k
hmm... i agree. it would be nice to have this one. cause its not hard to implement that "brand new feature". its only a matter of few seconds(?!) i guess.
Code: Select all
Procedure MyRandom(Min.l, Max.l)
Result.l=Random(Max-Min)+Min
ProcedureReturn Result
EndProcedure
MessageRequester("your lucky number is... ;)", Str(MyRandom(10, 20)))
p.s.: there is almost always a workaround, for almost everything, but still...
c ya,
nco2k
Posted: Fri May 20, 2005 11:41 pm
by Fred
Currently the command take 1 argument, which is max. So adding min as optional sounds wierd..
Posted: Fri May 20, 2005 11:42 pm
by Joakim Christiansen
I also want things to be easy, but I agree with Fred on this.
The random function is like this in every language(i think), why should it be different in PB.
Min-Max on random sounds quite stupid... (my personal feeling)
Posted: Sat May 21, 2005 2:04 am
by blueznl
pretty numb, but what the heck...
Code: Select all
Procedure.l x_random(low.l,high.l) ; generates a random int in the range low to high
;
; *** return a random var from and including 'low.l' to and including 'high.l'
;
; (i find the pb random function somewhat confusing now and again...)
;
ProcedureReturn low+Random(high-low)
EndProcedure
Posted: Sat May 21, 2005 3:57 am
by dracflamloc
Yea most randoms only return a float/double from 0 to 0.99999...
So you'd need to do rand()*10 to get an integer from 0 to 9 and add whatever constant you need for max/min, etc. Already easy enough. No change is my vote.
Posted: Sat May 21, 2005 8:33 am
by blueznl
it works, i'd rather add a rnd() for floats to emulate other languages than change the current one
Posted: Sat May 21, 2005 8:38 am
by Polo
nco2k wrote:hmm... i agree. it would be nice to have this one. cause its not hard to implement that "brand new feature". its only a matter of few seconds(?!) i guess.
Code: Select all
Procedure MyRandom(Min.l, Max.l)
Result.l=Random(Max-Min)+Min
ProcedureReturn Result
EndProcedure
MessageRequester("your lucky number is... ;)", Str(MyRandom(10, 20)))
p.s.: there is almost always a workaround, for almost everything, but still...
c ya,
nco2k
Here is what I want

And also, nobody is speaking of optional parameter

Posted: Sat May 21, 2005 10:24 am
by Gansta93
Joakim Christiansen wrote:I also want things to be easy, but I agree with Fred on this.
The random function is like this in every language(i think), why should it be different in PB.
Min-Max on random sounds quite stupid... (my personal feeling)
No, there are language where the Minimum parameter exists. And I agree with others, it would be useful.
If I remember well, in PHP and MIrc there is the parameter LowValue. I don't know for C, C++ etc.
Posted: Sat May 21, 2005 10:25 am
by PB
> nobody is speaking of optional parameter
It's not needed. Some things just need to be done by the programmer.
