## News:

*NEW* Current Version on STEAM16.793

Webchat:
Visit the chat

## Rand(Min,Max)??

#### Ian Price

I know that GLBasic supports random numbers in the form of RND(Max), but this always returns a value between 0 and the Max value.

Is there a command like RAND(Min, Max), where the command returns a value between (and inclusive of) the two values?

I have only skimmed through the Index, so maybe I missed a similar command. Does it exist, and if not, can it be added?

[EDIT] BTW I created a function to do this, but a built in command could be useful to newcomers.
I came. I saw. I played.

#### Moru

The normal behaviour of basic is to give a number between 0 and 0.9999. This one you multiply with whatever you want the range to be and then add the number you want to be the start of the range. If you want newcomers to have it easier, post your function for them to use too! That's what it's all about anyway, isn't it?

#### Kitty Hello

Hm... I though this RND would be theeasy to use:
For RND(5,7) I use:
5+RND(7-5)

#### Schranz0r

Hmm Gernot i think RND(0,9) for example, could be better then RND(9).
So you can do RND(5,10),  5 MIN 10 MAX....
Should be easier to use...

@ iprice

you can use that:

negativ and positiv values!

ex.: RAND(-10,10) or RAND(10,20) or something like

Code (glbasic) Select
`FUNCTION RAND: minimum, maximum RETURN minimum + RND(-minimum + maximum) ENDFUNCTION`
I DGArray's

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

#### Ian Price

Quote from: Schranz0rHmm Gernot i think RND(0,9) for example, could be better then RND(9).
So you can do RND(5,10),  5 MIN 10 MAX....
Should be easier to use...

@ iprice

you can use that:

negativ and positiv values!

ex.: RAND(-10,10) or RAND(10,20) or something like

Code (glbasic) Select
`FUNCTION RAND: minimum, maximum RETURN minimum + RND(-minimum + maximum) ENDFUNCTION`
That's very similar to the function I came up with
I came. I saw. I played.

#### Moru

Why is it every new Basic dialect has to come up with it's own way of using RND? Why not stay with the 0 - 0.9999 and leave the programmer to use it as he sees fit? If you want negative values you just do RND() * 20 - 10 and you have a range between -10 and +10.

#### Neurox

Quote from: MoruWhy not stay with the 0 - 0.9999 and leave the programmer to use it as he sees fit?
Sorry, but I prefer the GLBasic way!
It's very comfortable ;-)

Neurox
Paolo Borzini | paolo@borzini.it
The WhiteFly Software | www.thewhitefly.it
Service on line for screen printers | www.4pellicole.it

#### Schranz0r

Quote from: Neurox
Quote from: MoruWhy not stay with the 0 - 0.9999 and leave the programmer to use it as he sees fit?
Sorry, but I prefer the GLBasic way!
It's very comfortable ;-)

Neurox
GLBasic rockz
I DGArray's

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard