Random of 1 , -1 ? how?
POM
Member Posts: 2,599
hey guys, simple question :
how do i make an integer a random of 1 or -1 ?
if i use simple random like random(-1,1) it has the value "0" in it -> no good for me.
is there a simple way?
p.s
please dont say :
change temp to random(0,1)
if 0 :
change to -1
if 1
change to 1
Roy.
how do i make an integer a random of 1 or -1 ?
if i use simple random like random(-1,1) it has the value "0" in it -> no good for me.
is there a simple way?
p.s
please dont say :
change temp to random(0,1)
if 0 :
change to -1
if 1
change to 1
Roy.
Comments
If self.random = 2
Then self.random = -1
thanks for the quick reply
is there no other way to do this in just a simple change rule?
min, max? Nope, don't think so.
Inverse Sine?
(There's a nice screenshot/graph on my website)
http://photics.com/books/gamesalad-textbook
-1 to 1... but it could fall anywhere in there.
What's wrong with an extra rule?
2*random(-1,0)+1
(Haven't tried this but, theoretically, it should work.)
@Photics
Nothing wrong with extra rule, im just trying to learn how expert developer should do stuff..
I put... Then self.random= -1
not...
Then self.random = self.random-1
(-1)^random(0,1)
(-1) to the zero power?
It works, not sure why though.
...anything to the zero power is 1.
...and something to the power of 1 is itself.
so simple but yet very interesting.
Lets see if anyone comes with some more ideas.. just for fun (and for proof that you might be like codemonkey one day HAHA)