- Joined
- Jul 18, 2008
- Messages
- 4,866
Truly Randomizing your Spells and Functions
By WherewolfTherewolfEdit: I wrote this tutorial before i know about the "Fixed Random Seed" option (turn it off to remove the horrible unrandomness in testing, it should be in preferences under file in your editer), so this is kind of useless, though the game still never creates a perfect random integer, but the idea to use a player cameras x or y is a pretty good idea for getting a random integer.
Every mappers probably used the "random integer" function at least once. But is it truly random? And if it isn't, how can i evade this issue? I made this tutorial to explain how, why and how to get around a pattern issue with Blizzard's random integer function (also random point, random real, random angle...)
Ill do this in 3 parts, if you don't really care how or why, just skip the first 2. If you want to know why just keep reading.
Why?
A machine is built for one purpose, to take something, its input (ex. force), complete a process and produce an output (ex. lets say Flying Sheep). To the very nature of this process, it will always need and input and a set process to provide an output. To how this pertains to the function is found in math, take these equations:1+1=2
x-2=0 x=2
x^2=4 x=2
2x-2=2 x=2
What is common about all of these equations? They all equal 2. There's no way to change that, 2+2=4 and that is completely and utterly true. So to its nature, math is definite. So how do you come up with a completely random value in math? You don't, math is etched in stone and cannot be altered.
So how does this pertain to warcraft at all?
Warcrafts random number generator is a formula (one I have yet to figure out).
In essence, warcraft takes its input (the max and min values you give), does its process (the formula) and gives and output (the supposedly "Random" number).
So how come it is called random?
How?
I have to say, though it has a pattern, Blizzards random int formula works well for what it is supposed to do. The formula will not give the same output twice in a sequence of random numbers unless it has been forced to (random int between 1 and 2, not many options). This is in sense pretty good for random and may appear random the first time. But to see why its not random do this:
Create a map
Remove the triggers from the init trigger.
Make it so it does this on init, Display Messege - convert integer to string - random number between 1 and 100.
1 and 100 is a large domain so you think the game would have no issue coming up with a random int.
Test it.
Now restart it. It will give you the same integer everytime you restart the map.
This can be shown with random location, random real, random angle, basically anything random.
So now that you know why it does this, heres how to get around it.
How do I get around this?
Since math is concrete, you may think you have no chance at true randomness. But that is wrong. Since you cant achieve random through the game you'll have to tap another source (I'm making this sound more complicated then it really is).
The Human mind works differently then a computer, it can create and make new. In essence, you need a biotic factor to have actual randomness.
So here's how to use this:
The game will not give you the same value twice, though it will use the sequence every time IF not interrupted.
SO, if you make the game constantly set a pointless random value every so many iterations (i would say 1/100's of a second) it will start to make a changing list.
Now when you want randomness, rely on the player. Have a player triggered event set off the random spell, trigger, etc. You can turn off the random int cycling trigger after this.
Think about it, waits the probability you'll type or cast a spell at the EXACT same time you did it the last time? There's a minuscule chance you'll achieve this. So since the integer was being randomized and the player disrupted the sequence, the game will give different outcomes.
Here's an example:
In Dotgay style, a spell that stuns for a random period of time.
================================================================
- Random Cycling Trigger:
- Events:
- Periodic Time - .01 seconds
- Conditions:
- (none needed)
- Actions:
- Set (insert pointless integer variable here) = Random number between 1 and 100
- Cycle Int on Spells
- Events:
- A unit (any spell event)
- Conditions:
- Dont need any
- Actions:
- Set (insert pointless integer variable here) = Random number between 1 and 100
- Dotgay Random Stun Spell
- Events:
- A unit (whatever spell event you want (begins casting, starts the effect, etc.)
- Conditions:
- Ability Being Cast = Dotgay gay Stunner
- Actions:
- Set variable, or udg, Dotgay Stun Time [index] = Random Integer (or real, whatever you prefer) between (min stun time) and (Max Stun Time)
- Set Dotgay Stun Target (player number owner of casting unit,if you want to get technical) = Target unit of ability being cast
- Pause Dotgay Stun Target [Inset Index]
- Wait (start a timer if you want) Dotgay Stun Time [Index]
- Unpause Dotgay Stun Target [Index]
In that, the target was paused for a random amount of time. Now you can add effects and stuff if you want, but look for a different tutorial for that.
This is just one example of getting around the random int pattern. There are other ways, for example cycling the random int every time a unit casts any spell (just leave conditions blank).
Since there's barely any chance people will cast spells at the exact same time, the same amount of times this would work too in cycling randoms.
When using this, you wont have to cycle a random for every type (you don't have to repeat this for real and point values).
I hope this was helpful, please comment if you find this confusing or spelling errors (I seem to make them a lot, and this was typed up in notepad so i didn't use spell check).
-Wherewolf
Last edited: