This site requires JavaScript, please enable it in your browser!
Greenfoot back
Miguel.Valdez
Miguel.Valdez wrote ...

2018/3/28

turning at a random angle between -45 and +45 degrees.

Miguel.Valdez Miguel.Valdez

2018/3/28

#
my theory is this (code provided) to make it change a random angle between -45 and +45 degrees. but not sure if correct.
1
private int randomTurnAngle = Greenfoot.getRandomNumber(46)-91;
danpost danpost

2018/3/28

#
Miguel.Valdez wrote...
my theory is this (code provided) to make it change a random angle between -45 and +45 degrees. but not sure if correct.
1
private int randomTurnAngle = Greenfoot.getRandomNumber(46)-91;
Your values are a bit backwards. You have 91 choices and a beginning value of -45.
Miguel.Valdez Miguel.Valdez

2018/3/28

#
So what should my values be for it to change between a random angle between-45 and +45? Ex: -45,-44,-43,-42....20,21,22.....42,43,44,45.
Miguel.Valdez Miguel.Valdez

2018/3/28

#
danpost wrote...
Miguel.Valdez wrote...
my theory is this (code provided) to make it change a random angle between -45 and +45 degrees. but not sure if correct.
1
private int randomTurnAngle = Greenfoot.getRandomNumber(46)-91;
Your values are a bit backwards. You have 91 choices and a beginning value of -45.
so it should be
1
private int randomTurnAngle = Greenfoot.getRandomNumber(91)-45;
because i have choices from 0 to 90.... and 0-45=--45, so my wouldnt my lowest choice would be -44(when i need it to be between -45 and +45) & 91-45=46, so my highest option being 45(this is correct)? so -44 wouldnt work. -45 needs to be an option.
danpost danpost

2018/3/28

#
Miguel.Valdez wrote...
because i have choices from 0 to 90
That is correct. There is no 91 in this. min: 0 - 45 = -45 max: 90 - 45 = 45 The 91 random values consist of the positive numbers from 1 to 90 (giving 90 choices) and zero is the other possible random value (giving 1 more choice).
Miguel.Valdez Miguel.Valdez

2018/3/28

#
Yes, oops I meant 90.... Nd ok I get you, this really cleared a lot up for me on new ways in how to use .getRandomNumber()
You need to login to post a reply.