Random help needed

stanimationstanimation Member Posts: 406
edited November -1 in Working with GS (Mac)
I'm trying to figure out a random rule. Here is an example:

(ceil(random(-.99,.99))*180)+90

The problem is I don't think the ceil is working with the negative number. I need to generate random 0 and 1. Any help would be appreciated!! Thanks!!

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    You cannot have real numbers in the random function, only integers.

    What is final range of numbers that you are looking for?
  • stanimationstanimation Member Posts: 406
    Hey FMG, I am trying to figure out how to get two to four specific (that can be specified) numbers in a random fashion. For example if I chose 180 and 90, when called it will randomly select one of the two. Same with four numbers. Thanks for any help!!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Well, one way, without any math, would be this:

    Change Attribute
    self.myRandomNumber To: random(1,4)

    Rule
    When all conditions are valid:
    self.myRandomNumber = 1
    Change Attribute: self.chosenNumber To: 180

    Rule
    When all conditions are valid:
    self.myRandomNumber = 2
    Change Attribute: self.chosenNumber To: 90

    etc...

    However, since those two numbers are mathematically related nicely, you could do this:

    Change Attribute
    self.myRandomNumber To: (random(0,1) * 90) + 90

    That will give you EITHER 90 or 180.

    What are the other two numbers? Maybe they can easily work as well.
  • stanimationstanimation Member Posts: 406
    actually I'm trying to have a random east west move or a random north south or a combination of those movements. I thought I needed to use the ceil function but I guess not.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Change Attribute
    self.myRandomDirection To: (random(0,3) * 90) + 90

    That will give you either 90,180, 270, or 360(0)

    Is that sort of what you were thinking?
  • stanimationstanimation Member Posts: 406
    That should do it! Thanks man. Easier than I thought. You rock!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Cool! Glad I could help.

    I haven't tested it, but you MIGHT need to wrap the whole thing in a modulus function to make sure it wraps back to zero, like this:

    Change Attribute
    self.myRandomDirection To: ((random(0,3) * 90) + 90)%360

    Which will give you either 90,180, 270, or 0
    (the 360 will be forced back to zero)
  • stanimationstanimation Member Posts: 406
    Cool. I cant wait to test it tonight. Thanks Joe!
Sign In or Register to comment.