GLBasic forum

Codesnippets => Code Snippets => Topic started by: monono on 2010-Oct-01

Title: Small random function
Post by: monono on 2010-Oct-01
I use this quite extensively:
Code (glbasic) Select

FUNCTION QRND: b, e=0 , scale=1
LOCAL n = ABS(e-b)
RETURN b+ n/(scale*n)*RND(scale*n)
ENDFUNCTION


Examples:
QRND(20) - nothing special, like RND(20)
QRND(20,100) - numbers between 20 and 100
QRND(20,100,10) -numbers between 20 and 100 and 10 steps from one number to the next one  20,20.1...99.9,100
and so on..
Works with negative numbers.
Title: Re: Small random function
Post by: Scott_AW on 2010-Oct-01
That is a nice function, I always go about just adding and subtracting after the random, this would be less typing and easier to handle.
Title: Re: Small random function
Post by: monono on 2010-Oct-02
You're welcome.