How random is random?

Mr Zero

Junior Regular (Got the T-shirt)
Reaction score
64
Sorry for bumping but you said you had 26 in many rows?
Well I has look at this tutorial. Look in the buttom;
Darthfett said:
Test Map

This will automatically open warcraft with your map, without you having to go through the hassle of finding your map, and opening it. If you have the Preference option "Use Fixed Random Seed" Checked, then whenever a random number is picked, it will be used every time, so you can check to see if everything works.

That's why! :)
 

Chocobo

White-Flower
Reaction score
409
PHP:
#include <stdio.h>   // printf(), getchar(), puts()
// three different custom random number generators
int rand1(int lim);
int rand2(int lim);
int rand3(int lim);
int main(void)
{
        int  k, rnd1, rnd2, rnd3, sum1, sum2, sum3;
        sum1 = sum2 = sum3 = 0;
        puts("Random numbers between 1 and 44:\n");
        printf("%15s%10s %10s %10s","Custom functions","rnd1()","rnd2()","rnd3()");
        for (k = 0; k < 40; k++) {
                rnd1 = rand1(44);
                rnd2 = rand2(44);
                rnd3 = rand3(44);
                printf("\n%25d %10d %10d",rnd1,rnd2,rnd3);
                sum1 += rnd1;  
                sum2 += rnd2;
                sum3 += rnd3;
        }
        printf("\n\n%15s%10d %10d %10d   (ideal 22)\n",
        "   Average:",sum1/k,sum2/k,sum3/k);
        getchar();
        return 0;
}
int rand1(int lim)
{
        static long a = 100001;
        a = (a * 125) % 2796203;
        return ((a % lim) + 1);
}
int rand2(int lim)
{
        static long a = 1;
        a = (a * 32719 + 3) % 32749;
        return ((a % lim) + 1);
}
int rand3(int lim)
{
        static long a = 3;
        a = (((a * 214013L + 2531011L) >> 16) & 32767);
        return ((a % lim) + 1);
}

I don't know if that can help.. someone wrote it for me on 1 hour only lol. (C++)

You should be able to convert this to JASS.

PHP:
//For the first function I don't know how you will do a conversion.

PHP:
function rand1 takes integer lim returns integer
        local integer a = 100001
        a = (a * 125) % 2796203 //I don't remember what the % stands exactly for.
        return ((a % lim) + 1) //So does there.
endfunction

PHP:
function rand2 takes integer lim returns integer
        local integer a = 1
        a = (a*32719+3) % 32749 //Again the %
        return ((a % lim) + 1) //So does there.
endfunction

PHP:
function rand3 takes integer lim returns integer
        local integer a = 3
        a = (((a * 214013L + 2531011L) >> 16) & 32767) //I don't know what stands &, L, and >> for
        return ((a % lim) + 1) //Again the %
endfunction
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
In C, "%" is the "modulo" operator.


Don't fix what isn't broken.

Not to mention that JASS doesn't have a "shift right" operator (">>"),
And it doesn't have a binary "and" either ("&").

The "L" just indicates the "long" version of that number.
Which dates back to the times when compilers still used 16bit integers, and you had to tell them that you actually need a 32bit quantity.


This is also completely off topic.
 

New_U.S.

ITS OVER 9000!
Reaction score
125
For everyone that has this problem and is to lazy to read all the post here is why it isnt random and (my) way to fix it-

Computers just do a wierd math problem that seems random to us but its really not

If your numbers are to small (ex- your get a random number between 1 and 25) you will get the same number to repeated often (usually)

A good way to fix this is double up the random numbers and have 2 numbers equal the same thing (1 = 1, 50 = 1)

There are probably better ways (I didnt read all the posts :D )

*-Just a Summery-*
 

Joker(Div)

Always Here..
Reaction score
86
GetRandomInt isnt completely random. I had a AoS game that selected a random int ( had my heros as integers ) and I always random the same hero 5 out of 5 times.
 

SFilip

Gone but not forgotten
Reaction score
634
You sure it wasn't on test map (check out post 21)?
 

Knights

You can change this now in User CP.
Reaction score
71
Well..

Since this has been brought back up..


If you ran a trigger which would produce a random integer from 1-100 every second..it would NEARLY always start with a specific number. This is often caused by a fault in the random number script, but we know this is not the case.

To best explain why, I'll take the example pulling numbers from a bag.

Here is the scenario:
-Somone cuts 50 pieces of paper
-They write 1-50 on them
-They put them in a bag starting with 1, 2, 3, 4...50
-They draw a number out

It is most likely that number will be high, as the low numbers were put in first.


My belief is that computers work the same way. They generate the numbers in an order based on criteria, and it works the same way as pulling numbers out of a bag.


Here is a visual:

10
9
8
7
6
5
4
3
2
1

We pick from this pile..the number 10, because it is on top.

When we throw the number back in the arrangement, it now looks like:

9
10
8
7
6
5
4
3
2
1

..When we next pick a number, it is 9.

Then the arrangement looks like:

9
8
10
7
6
5
4
3
2
1

Etc..etc...as time goes on, it gets more mixed up and more mixed up, eventually looking like:

5
8
2
4
1
7
3
9
6
10


SO....my solution??

Generate a lot of random numbers, BUT DO NOT USE THESE ONES!!

THEN, generate a random number and display it how you wish..or use it for whatever you wish.


THAT should get you the most random number possible.

Hope that helps,
Knights:cool:
 
G

g1real

Guest
Best solution to get random numbers perfectly (I never used random seeds =P).

Get 200 numbers (if you used 36 at first, get 720) (so number * 20)

Then use If number is higher then 0, and lower/equal to 72 do:
If number higher/equal to 73 and lower/equal to 144, then do..
etc.

I think that works best.
Also I agree with what acehart says, random is random, because you don't expect what results come from. Wanna bet that if you'd expect another 26 or another blademaster you'd get something else? The computer reaaaadsss your mind.

~~Just trying to help~~
 

Almighty11

New Member
Reaction score
5
Well i myself have some experience from random numbers and i know problems like that happen much likely.

I once tried some experiences with a random number generator and software called 'tasker'. I just used the tasker to generate the numbers (tasker repeats command sequences that you order how many times you want) and then paste it into a noteblock. But after pasting, i ordered it to use CTRL+F (locate if that number alredy existed) and if it existed, it would be replaced by itself. If that happened, tasker would make a registry (copying 1-10000 number there, in sequence) , so i could track how many times numbers repeated. Out of a HUGE possibility (like 10 or more digits, i dont remeber), and like 1000 times task repeated (also dont remeber exactly), numbers repeated like 600~ times. Is that random?

The thing is that random doesnt exists : it is always based in something. If you are then good in statistics, you should know that the most likely thing in any sequence is to numbers not repeat. There is a much smaller chance for it to repeat, so thre might be an error or some mistake on random basing. I think that adding more 'random masks' to it would work. For exemple :

You take a random number from 0-10 sequence. for each number, take 1 out of 5 random number from a random sequence. If that doesnt work, no idea.
This is something that will always be a problem in computer, until the day QUANTUM COMPUTERS come xD
 

Some1Sneakin

New Member
Reaction score
5
I did play "X hero siege" with my friend,

If you pick a random hero you have 1 of 25 chanse to play as the final boss (ghost).

In the first game: Both me and my friend got the ghost randomy picked!
In the second game: Only my friend got the ghost randomy picked!

Really random LOL!
 
K

Kevin

Guest
What you're experiencing is something called a Harmonic Number.

I had to tackle the problem of Harmonic Numbers when I was busy creating an artificial irrational number (btw this is something nobody else has done in the world, I stuck it in my sci fi book and am now trying to get published).

The only way to eliminate Harmonic number is if you stick an ever increasing increasing integer into the equation.

WE doesn't have the capacity to do this, it'd crash the game. Hell, it took me to calculate to the 48 billion range before I realized how the haromic number worked, the standard calculator's max can't reach even the 16th decimal place.

IN otherwords, unless you want to modify your harmonic number with a heavy duty series of equations, just leave it be.
 
G

g1real

Guest
If i would type 10 rows of random numbers.. do you see a pattern?

68431977543150379
13864689674084934
06871643148732456
24873876513549876
41379871636746437
37486948463106179
12108454721472349

Meep, no, not really.
Tell me then, what pattern does a computer do, or at least, world editor do? well? huh?
HUH?

Hehe...... hehehe...

Oh sorry, im just bullshitting, but I still agree with acehart.. random is random cause you don't expect it, try randoming dota heroes.. if you get the same each time. And then you think "oh.. now i get it again". You wont!
 
K

Kevin

Guest
Harmonic Numbers appear random at first, but turn out not to be random.
 
S

scythetleppo

Guest
chance to roll a 1 on a 1-4 random: 25%

chance to roll it again: 25%

chance to roll it again: 25%

and again: 25%


random doesn't store results

if you want a TRULY random effect, do this simple thing.

write down the options on paper, then put each in identical envelopes and mail them to the same bad address. whichever one comes back first is the one you put in your map =D

but seriously though, there are numerous ways to do random numbers, such as:

detecting the current coordinates of a moving unit and adding that to the number that random comes up with. in many circumstances that would be truly random, and totally unexploitable.

also you could detect the amount of seconds passed since the beginning of the map, and add that to your generated number.

you see what im saying? think of something REAL that is random, such as how many creeps have died minus the time of day plus the number of items in the map....

i mean seriously it's not too complicated..
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top