Random integer number

nLike

Member
Reaction score
1
I have a variable that i'm using for something. Every few seconds I give it a random value between 1-4 but I need it to be different from what it was before.

I've been trying to find a solution but I can't seem to find anything smart. Is it possible to exclude a number in a random group from to?
 

maxou

You can change this now in User CP.
Reaction score
15
You can do a While/WhileEnd loop with this:

For each C from 1 to 2
| set Random_Number = Random number between 1 and 4
| If Random_Number = Last_Random_Number
| | Then
| | set C = (C - 1)
| | Else
| | set C = 2
| set Last Random_Number = Random_Number
Do my thing with my Random_Number blablabla..

Here you are :D
Variables : C (Integer), Random_Number (Integer), Last_Random_Number (Integer)
 

Imp Midna

Active Member
Reaction score
52
thats a strange solution. i mean, just in case you got really bad luck, the trigger will fail at getting the random number xD
why cant you just use Random number between 1 and 3 and add 1 if the number equals / is bigger then the last random number?
 

maxou

You can change this now in User CP.
Reaction score
15
It's a solution, but the trigger can't fail, he'll find a number everytime.

Actually, if he finds a number which is the last number, he'll search another number, if it's the same again, he'll search again another number untill he finally find a new number.
 

death_knight

Dark is the heart of a corrupted man.
Reaction score
24
Well how about this:

Trigger:
  • Trigger
    • Events
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (int_A Equal to 1) or (int_A Equal to 2)
        • Then - Actions
          • Set int_B[2] = (Random integer number between 1 and 4)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • int_B[1] Equal to int_B[2]
            • Then - Actions
              • Trigger - Run (This trigger) (checking conditions)
            • Else - Actions
              • Set int_A = (int_A + 1)
              • Trigger - Run (This trigger) (checking conditions)
        • Else - Actions


This will work if you set int_A to one and then run the trigger from another trigger. I've used triggers very similar to this one and they've done the job very well. Hope this helps.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top