| View previous topic :: View next topic |
| Author |
Message |
bgbirdsey Developer

Joined: 25 Sep 2007 Posts: 862 Location: Minnesota
|
Posted: Fri May 30, 2008 11:59 pm Post subject: |
|
|
| Quote: | | rand & 2 generates a number between 0 and 2. |
GARRRR! The & is a bitwise operator. If you misuse it, have a lapse in judgement, or don't understand binary it is better to use the % operator instead.
rand % n generates a number between 0 and n-1
here is simple table of the results of using rand and &
rand & 1 generates a random number between 0 and 1.
rand & 3 generates a random number between 0 and 3.
rand & 7 generates a random number between 0 and 7.
rand & 15 generates a random number between 0 and 15.
rand & 31 generates a random number between 0 and 31.
rand & 63 generates a random number between 0 and 63.
rand & 127 generates a random number between 0 and 127.
rand & 255 generates a random number between 0 and 255.
rand & 511 generates a random number between 0 and 511.
and so on
rand & 2 generates EITHER 0 or 2
rand & 4 generates EITHER 0 or 4
rand & 8 generates EITHER 0 or 8
rand & 16 generates EITHER 0 or 16
rand & 32 generates EITHER 0 or 32
rand & 64 generates EITHER 0 or 64
and so on |
|
| Back to top |
|
 |
Clonkinator Master Frying Pen (Moderator)


Joined: 03 Nov 2007 Age: 16 Posts: 3074 Location: Germany
|
Posted: Sat May 31, 2008 7:20 am Post subject: |
|
|
| penguinflyer2222 wrote: | | On page one I noticed that Zefz and AoD double posted. |
It's right that there are two posts in a row from them but they're all several days apart from each other; after about 24 hours it's not really called double-posting anymore. Thanks for saying it though.
(However, since such stuff usually is off-topic, please just PM me about it next time) _________________ Yes, it's true. I fail. Epicly so. |
|
| Back to top |
|
 |
PurpleSquerkle Supreme Cookiemancer


Joined: 28 Oct 2007 Age: 17 Posts: 4356 Location: Midwestern US
|
Posted: Sat May 31, 2008 2:51 pm Post subject: |
|
|
Also, this is a pretty old thread.
We were way more lenient back when there were only five or six active members.
| bgbirdsey wrote: | | Quote: | | rand & 2 generates a number between 0 and 2. |
GARRRR! The & is a bitwise operator. If you misuse it, have a lapse in judgement, or don't understand binary it is better to use the % operator instead.
rand % n generates a number between 0 and n-1
here is simple table of the results of using rand and &
rand & 1 generates a random number between 0 and 1.
rand & 3 generates a random number between 0 and 3.
rand & 7 generates a random number between 0 and 7.
rand & 15 generates a random number between 0 and 15.
rand & 31 generates a random number between 0 and 31.
rand & 63 generates a random number between 0 and 63.
rand & 127 generates a random number between 0 and 127.
rand & 255 generates a random number between 0 and 255.
rand & 511 generates a random number between 0 and 511.
and so on
rand & 2 generates EITHER 0 or 2
rand & 4 generates EITHER 0 or 4
rand & 8 generates EITHER 0 or 8
rand & 16 generates EITHER 0 or 16
rand & 32 generates EITHER 0 or 32
rand & 64 generates EITHER 0 or 64
and so on |
OK, so what does "rand & 1000" do, exactly?
Either 0 or 1000?
Hmm. Interesting.
I might have to keep working and see if I can get something even better, then. _________________
+ PurpleSquerkle
--My website--
Latest update= 7/15/08; Three new midi loops.
{new Squerkle coming as soon as I stop being lazy} |
|
| Back to top |
|
 |
Zefz Lead Designer


Joined: 16 Sep 2007 Posts: 2301 Location: Norway
|
Posted: Sat May 31, 2008 4:45 pm Post subject: |
|
|
Thats why I suggested using rand & 1023
And I was a little confused when you said it did not work properly. _________________ http://egoboo.sourceforge.net
"The pen is mightier than the sword- IF it is sharpened, dipped in poison and thrown really really hard at your target. But seriously, you are better off with a sword." |
|
| Back to top |
|
 |
PurpleSquerkle Supreme Cookiemancer


Joined: 28 Oct 2007 Age: 17 Posts: 4356 Location: Midwestern US
|
Posted: Sat May 31, 2008 5:20 pm Post subject: |
|
|
It doesn't!
Seriously, try it.
It just doesn't work.
What's another good one I could use? _________________
+ PurpleSquerkle
--My website--
Latest update= 7/15/08; Three new midi loops.
{new Squerkle coming as soon as I stop being lazy} |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|