Random number excluding current number?
I have an event that will then choose a random number from 1 to 150.
That's easy, but how would I make exclude it's Oriningal number.
So self.number is 3
Event happens
Change self.number to random(1,150) (but excluding the number 3 as that was what it was previously)
So far I made a rule that has another attribute that changes to the Oriningal number and then after event if that attribute is equal to self.number then it picked the same number so then it's repeated until they are no longer the same.
Question:
Is there away I can out it into a forumula that just excludes the Oriningal number?
Thanks
That's easy, but how would I make exclude it's Oriningal number.
So self.number is 3
Event happens
Change self.number to random(1,150) (but excluding the number 3 as that was what it was previously)
So far I made a rule that has another attribute that changes to the Oriningal number and then after event if that attribute is equal to self.number then it picked the same number so then it's repeated until they are no longer the same.
Question:
Is there away I can out it into a forumula that just excludes the Oriningal number?
Thanks
Best Answers
-
Socks London, UK.Posts: 12,822
Try something like this:
(Random (1,150)+original number)%150
(Might need a little tuning)
Answers
I think (correct me if I'm wrong) if self number is 1 and the random selection is 0 then you can get two (or more) 1’s in a row ? My version (essentially the same deal as yours) has the same issue, hence the 'might need a little tuning'.
. . . unless I'm missing something ?
Think of it this way...You have the numbers 1 through 150 lined up in a circle. You have your starting number and you want a different number in that circle, so there are 149 other spots in that circle. So you need to add a random number between 1 and 149 to that number. But since a mod function returns a number between 0 and the max number-1, you need to normalize it by first subtracting 1 from the original number then adding 1 back after the mod, so your results will be in the set of 1-150 instead of 0-149.
You're good, very good !!
Yep! I spotted that just now ! (See post above).
Simple but clever !
Thanks, however, How can I type in the "mod" bit?
That's where I though it would be, but it's not nor anything similar. My guess is that because, for the time being I am on 0.92 I may not have it?!
(self.Number+random(0,148))%150+1
Works quite nicely now thank you, I tried altering @socks but it was working. Thank you both