RANDOM Numbers with negative range

Previous topic - Next topic

aroldo

This sounds silly but how can I usee the RND function to generate a random number between -1 and 1? Instead of 0-1?
[a http://apd-games.com/][img http://apd-games.com/images/APDGames135.png][/a]
MacBook Pro OS X El Capitan
XCode Version 7
iPhone 6 running  iOS 9
iPad Mini running  iOS 7.1
Galaxy S5
Dell Latitude Windows 8 Enterprise
Palm Pre, Palm Pre2

spicypixel

http://www.spicypixel.net | http://www.facebook.com/SpicyPixel.NET

Comps Owned - ZX.81, ZX.48K, ZX.128K+2, Vic20, C64, Atari-ST, A500.600.1200, PC, Apple Mini-Mac.

erico

Only integers or do you need float point?

aroldo

#3
Thank you spicypixel and erico,

For float I did this:

Code (glbasic) Select
LOCAL r# = (RND(20)*0.1)-1 // Genereates random numbers from -0.9 to 0.9
[a http://apd-games.com/][img http://apd-games.com/images/APDGames135.png][/a]
MacBook Pro OS X El Capitan
XCode Version 7
iPhone 6 running  iOS 9
iPad Mini running  iOS 7.1
Galaxy S5
Dell Latitude Windows 8 Enterprise
Palm Pre, Palm Pre2