Author Topic: Small random function  (Read 1703 times)

Offline monono

  • Mr. Polyvector
  • ***
  • Posts: 213
    • View Profile
    • Sockel Lernmedien
Small random function
« 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.

Offline Scott_AW

  • Mr. Polyvector
  • ***
  • Posts: 214
    • View Profile
    • SAW Game Design
Re: Small random function
« Reply #1 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.
Current Project, Orbital Contract Defense
http://gamejolt.com/games/adventure/code-name-ocd/9887/

BlackShadow now open source/resource(requires duke3d)
http://gamejolt.com/games/adventure/black-shadow-3d/9885/

Offline monono

  • Mr. Polyvector
  • ***
  • Posts: 213
    • View Profile
    • Sockel Lernmedien
Re: Small random function
« Reply #2 on: 2010-Oct-02 »
You're welcome.