# random boolean + reverse equation?

#### Jonforum

##### Veteran
hi, there is a more elegant way to write this code ?
in my context, i would like to inverse the proprety easeX but randomly.

PHP:
``````            if(Boolean(Math.round(Math.random()))){ obj.easeX = ~obj.easeX+1;};
if(Boolean(Math.round(Math.random()))){ obj.easeY = ~obj.easeY+1;};``````
if one have a beter sugestion.
because it is a little heavy for make a simple random reverse.
but I can't imagine another way cleaner.
thank you

Last edited:

#### Clock Out

##### Veteran
So the code should flip the sign of the number and the expression of the if statement generates either a 1 or 0. I think this can be simplified.
Code:
``````if (Math.random() < 0.5) {
obj.easeX  *= -1;
}``````

#### Jonforum

##### Veteran
yes thank you, after sleeping, the solution jumps to my eyes, these fascinate how the brain becomes useless with exhaustion.

PHP:
``````var end = (function(){ //register Closures setup
var easeX = setup.xStrength||0;
var easeY = setup.yStrength||0;
var rot = setup.rotStrength||0;
var time = setup.time||100;
var oX = pixiBox.x;
var oY = pixiBox.y;
return function(obj){
var rand1 = Math.random();
var rand2 = Math.random();
if(rand1>0.5){ easeX = ~easeX+1;};
if(rand2>0.5){easeY = ~easeY+1;};
this._valuesEnd = {x:oX+(rand1*easeX+1), y:oY+(rand2*easeY+1), rotation:(rand1*rot)/100 };
this.duration(rand1*time+time);
this.start();
};
})();``````

### Latest Profile Posts

Steam has announced a new feature to let people switch between playing on PC and on Steam Deck with the same save. I'll come back to add support for it to my steam plugins when the time comes.
Hang on, let me get my glasses...
Bust Status 1!
Animated lipsynch as well as lineart. Just lineart so far...

2 FPS 5 FPS Static