Wc3C.net [SNIPPET] PseudoRandom_Index
 Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar

 12-14-2011, 08:00 AM #16 Bribe User     Join Date: Mar 2010 Posts: 233 Submissions (1) It just makes the game not able to be reloaded? I thought it was something more obscure and harder to detect. Ok, that's easy enough to test. I will do that tonight (German time).
12-14-2011, 06:03 PM   #17
master of fugue

Join Date: Jun 2007
Posts: 2,453

Submissions (5)

Quote:
 Originally Posted by tamisrah I would totally prefer a small tutorial on how to create those functions over this snippet. xD

For this to work we need a base 2 size.
Let us pick 2^3 = 8 as base size for our example.

We need to create a circular pseudorandom function for numbers: 0 1 2 3 4 5 6 7
First index (seed) is always 1.
We need a multiplicator M and addition factor A
Our function always looks like this: seed = (seed * M + A) mod B
Let us try M == 3 and A == 1
seed[1] = 1
seed[2] = 1*3 + 1 = 4
seed[3] = 4*3 + 1 = 13 // we got a number over 8 so we do 13 mod 8 = 5
seed[4] = 5*3 + 1 = 16 // 16 mod 8 = 0
seed[5] = 0*3 + 1 = 1

We have reached 1 and completed our circle.
But it is not a full circle because we only got indexes: 1 4 5 0 (half circle)
We can never create indexes 2 3 6 7 with this function, it is not good.

We need to experiment a little more.
Lets try M == 5 and A == 1
seed[1] = 1
seed[2] = 1*5 + 1 = 6
seed[3] = 6*5 + 1 = 31 -> 7 // remember the modulo 8
seed[4] = 7*5 + 1 = 36 -> 4
seed[5] = 4*5 + 1 = 21 -> 5
seed[6] = 5*5 + 1 = 26 -> 2
seed[7] = 2*5 + 1 = 11 -> 3
seed[8] = 3*5 + 1 = 16 -> 0
seed[9] = 0*5 + 1 = 1

Yeah we got full circle.

Things to remember:
B - Base should be power of 2. (2 4 8 16 32 64 128 ...)
M - Multiplicator should be odd number. (1 3 5 7 9.....)
A - Addition factor should be odd number. (1 3 5 7 9.....)

You always start with seed 1 and test until you go back to seed 1.
function always looks like this: seed = (seed * M + A) mod B
__________________
Omg database crash deleted my signature, as a side effect this immensely improved wc3c.

Last edited by cohadar : 12-14-2011 at 06:03 PM.