# Pick a Random Integer

Discussion in '"Graveyard"' started by kuyanutay, Nov 13, 2011.

1. ### kuyanutay

Joined:
Dec 11, 2010
Messages:
2
Resources:
0
Resources:
0
How to Use "Pick a Random Integer"

You may have seen this option in GUI before. Maybe that's why you viewed this tutorial. It appears in Math, and it is called Random Number.

With this function, you can have random events, numbers, or rewards(you can use something else for this) appearing in your map.

To use this function, you must have a variable, which can be created at the Variable Editor. The variable must be an INTEGER.

After completing the task, you may proceed to step 1.

Step 1

Create the desired event. For this tutorial, we will use Time - Periodic Event.

• Random Integer
• Events
• Time - Every 2.00 seconds of game time
• Conditions
• Actions

You may also add a condition. If you want.

Step 2

Now set the variable. We will use E1 for the tutorial.

• Random Integer
• Events
• Time - Every 2.00 seconds of game time
• Conditions
• Actions
• Set E1 = (Random integer number between 1 and 2)

Once that is done, we will go to the tricky part.

Step 3

Now, you must create actions corresponding to the picked integers.

Create a new ACTION, then choose If Then Else Multiple Functions.

The "Then" will be the action corresponding to 1.

We will use "Hello World" as the "Then" for 1.

• Random Integer
• Events
• Time - Every 2.00 seconds of game time
• Conditions
• Actions
• Set E1 = (Random integer number between 1 and 2)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• E1 Equal to 1
• Then - Actions
• Game - Display to (All players) the text: Hello World!
• Else - Actions

For the integer 2, we will repeat these steps.

For this tutorial, we will use Hello Azeroth!

Since we are done with the trigger, put Do Nothing on the last Else.

The finished trigger will look like this:

• Random Integer
• Events
• Time - Every 2.00 seconds of game time
• Conditions
• Actions
• Set E1 = (Random integer number between 1 and 2)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• E1 Equal to 1
• Then - Actions
• Game - Display to (All players) the text: Hello World!
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• E1 Equal to 2
• Then - Actions
• Game - Display to (All players) the text: Hello Azeroth!
• Else - Actions
• Do nothing

Before you test out the map, go to File > Preferences > Test Map and disable Use Fixed Random Seed
Go check out the map, to see if you really got it right.
---------------------------------------
Have fun with random integers!

2. ### Maker

Joined:
Mar 6, 2006
Messages:
9,181
Resources:
17
Maps:
2
Spells:
14
Tutorials:
1
Resources:
17
This is how you should do the triggers:

Triggers

50% chance to do something:
• Random Integer
• Events
• Time - Every 2.00 seconds of game time
• Conditions
• Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Random integer number between 1 and 2) Equal to 1
• Then - Actions
• Game - Display to (All players) the text: Hello World!
• Else - Actions

50%/50% chance:
• Random Integer
• Events
• Time - Every 2.00 seconds of game time
• Conditions
• Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Random integer number between 1 and 2) Equal to 1
• Then - Actions
• Game - Display to (All players) the text: Hello World!
• Else - Actions
• Game - Display to (All players) the text: Hello Azeroth!

• Random Integer
• Events
• Time - Every 2.00 seconds of game time
• Conditions
• Actions
• Set E1 = (Random integer number between 1 and 3)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• E1 Equal to 1
• Then - Actions
• Game - Display to (All players) the text: Hello World!
• Else - Actions
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• E1 Equal to 2
• Then - Actions
• Game - Display to (All players) the text: Hello Azeroth!
• Else - Actions
• Game - Display to (All players) the text: It was the third option

This is quite simple tutorial, and might not need a tutorial at all.

Last edited: Nov 20, 2011
3. ### busterkomo

Joined:
Jun 17, 2007
Messages:
1,423
Resources:
1
Tutorials:
1
Resources:
1
Maker, your third trigger doesn't even make sense. The last else block can never be reached.

### Code Moderator

Joined:
Nov 11, 2006
Messages:
7,426
Resources:
18
Icons:
1
Spells:
4
Tutorials:
9
JASS:
4
Resources:
18
Yes, this is a bit too basic of a tutorial. For me to accept a tutorial about random integers specifically, it would need to discuss seeds and weights.

We already have tutorials for chances of doing things.

5. ### Magtheridon96

Joined:
Dec 12, 2008
Messages:
6,006
Resources:
26
Maps:
1
Spells:
8
Tutorials:
7
JASS:
10
Resources:
26
It can be a real. You'd use (Random real number between x and y).

• Do Nothing

._.
`call MakeGUIUsersCrash()`

Joined:
Oct 16, 2008
Messages:
9,674
Resources:
23
Models:
2
Packs:
1
Maps:
1
Spells:
16
Tutorials:
1
JASS:
2
Resources:
23
Its too simple I guess...

The only time I think that someone needs a tutorial for this is when:

1)He does not know what a random number is
2)He does not know how to use if-then-elses

7. ### -Kobas-

Joined:
Jan 17, 2010
Messages:
5,894
Resources:
28
Icons:
1
Tools:
2
Maps:
10
Spells:
4
Template:
5
Tutorials:
6
Resources:
28
I think, that it can be reached.

E1 can be 1 or 2 or 3 right,
Code (vJASS):

if E1 equal to  1 then
//xxxx
elseif E1 equal to 2 then
//xxxx
else (Where we check is E1 equal to 3 or any other number except 1 and 2)
//xxx
endif

Jass tags to make this look like code.

8. ### watermelon_1234

Joined:
Nov 18, 2007
Messages:
1,066
Resources:
10
Spells:
9
JASS:
1
Resources:
10
^
I assume he edited the trigger.

Anyway, I agree with the others that this is too simple to be a tutorial.

9. ### -Kobas-

Joined:
Jan 17, 2010
Messages:
5,894
Resources:
28
Icons:
1
Tools:
2
Maps:
10
Spells:
4
Template:
5
Tutorials:
6
Resources:
28
Oh, missed that.
Btw way to simple.

### Code Moderator

Joined:
Nov 11, 2006
Messages:
7,426
Resources:
18
Icons:
1
Spells:
4
Tutorials:
9
JASS:
4
Resources:
18
It has been a month without updates so I'm going to graveyard this for now.

Let me know if you want to update it to include more complex things, but otherwise it is off to the graveyard.