Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Plus or Minus random Function

Author
Message
=C=
20
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 15th Jun 2003 14:07
Some times I want to add an extra plus or minus factor, especially when I create objects in space, where their relative position is specified but I want to add an element of randomness.

So here it is, a cute one liner:



I hope you enjoy it and that it will get a small place in your code library. and in your hearts!

=C=
-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy
Blanka
21
Years of Service
User Offline
Joined: 26th Feb 2003
Location: United Kingdom
Posted: 18th Jun 2003 00:05
or if you just want 1 or -1 without 0 you could try this.


GameKit
21
Years of Service
User Offline
Joined: 6th Mar 2003
Location: USA, Staring Blankly at a Computer
Posted: 18th Jun 2003 07:44
or... for only a 1 or -1 in one line of code...

a=(rnd(1)-0.5)*2

...well...thats it...

Anyone Can Destroy...But Few Can Create...
=C=
20
Years of Service
User Offline
Joined: 8th May 2003
Location: United Kingdom
Posted: 22nd Jun 2003 20:58
Game Creator, this is the newest version I came up with too. I wont even bother posting it. Well done!

-------------------------------
Pointy birds, Oh pointy pointy
Anoint my head, Anointy 'nointy

Login to post a reply

Server time is: 2024-05-06 17:35:34
Your offset time is: 2024-05-06 17:35:34