
[Implemented] Random
[Implemented] Random
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 

- Joakim Christiansen
- Addict
- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
Code: Select all
Random(15)+5
I like logic, hence I dislike humans but love computers.
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.
p.s.: there is almost always a workaround, for almost everything, but still...
c ya,
nco2k

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)))

c ya,
nco2k
- Joakim Christiansen
- Addict
- Posts: 2452
- Joined: Wed Dec 22, 2004 4:12 pm
- Location: Norway
- Contact:
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)
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)
Last edited by Joakim Christiansen on Sat May 21, 2005 2:36 am, edited 1 time in total.
I like logic, hence I dislike humans but love computers.
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
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
- Addict
- Posts: 1648
- Joined: Mon Sep 20, 2004 3:52 pm
- Contact:
it works, i'd rather add a rnd() for floats to emulate other languages than change the current one
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
Here is what I wantnco2k 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.![]()
p.s.: there is almost always a workaround, for almost everything, but still...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)))
![]()
c ya,
nco2k

And also, nobody is speaking of optional parameter

No, there are language where the Minimum parameter exists. And I agree with others, it would be useful.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)
If I remember well, in PHP and MIrc there is the parameter LowValue. I don't know for C, C++ etc.