[Implemented] Random with max, min and type

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

[Implemented] Random with max, min and type

Post by techjunkie »

It would be nice with a random function where you could specify max and min. It also would be nice if you could use float as a parameter or you could specify what type you want in return.

For example...

Result.f = Random(0.4, 1.2)

or

Result.w = Random(600, 800)

I'm sure someone else must have come with the same request here before...
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
WolfgangS
Enthusiast
Enthusiast
Posts: 174
Joined: Fri Apr 25, 2003 3:30 pm

Post by WolfgangS »

Hi
In the meantime you can use this:

Code: Select all

hans.f=Random(8)/10+0.4
Debug hans.f
Debug SizeOf(hans)


sepp.w=Random(200)+600
Debug sepp.w
Debug SizeOf(sepp)
MFG
WolfgangS
WolfgangS' projects http://www.schliess.net
Quotation of the month:
<p3hicy>oder ich hol mir so eine geile aus asien
<p3hicy>die ständig poppen will
<p3hicy>'n brötchen pro tag reicht doch
<p3hicy>die essen eh' nich so viel
Kris_a
User
User
Posts: 92
Joined: Sun Feb 15, 2004 8:04 pm
Location: Manchester, UK

Post by Kris_a »

It's better than C's rand() at least - you can't even input a 'maximum' with that :D
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

WolfgangS wrote:Hi
In the meantime you can use this:

Code: Select all

hans.f=Random(8)/10+0.4
Debug hans.f
Debug SizeOf(hans)


sepp.w=Random(200)+600
Debug sepp.w
Debug SizeOf(sepp)
MFG
WolfgangS
Yes - thanks... It's just what I'm doing right now... But if you want very small number it is a lot of typing. For example... If you want a random number between 0.006 and 0.008.

Code: Select all

Debug ((Random(1000) *0.002)/1000 + 0.006)
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
guido
User
User
Posts: 14
Joined: Tue Nov 25, 2003 4:56 pm
Location: Old Europe - Germany

Post by guido »

techjunkie wrote:
Yes - thanks... It's just what I'm doing right now... But if you want very small number it is a lot of typing. For example... If you want a random number between 0.006 and 0.008.

Code: Select all

Debug ((Random(1000) *0.002)/1000 + 0.006)
Have you considered to write a function for it :wink:? I would hate to have a language bloated by stuff, which can easily be supplied using a few lines of code and doesn't look differently when looking at the high level (function call). C was divided to core language and a standard library for good reason...
guido
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

guido wrote:Have you considered to write a function for it :wink:?
:lol:

Of course I use a procedure, but it slow down things in critical code...

Thinking of doing it in assembler...
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
Post Reply