random how does it work ?

jonsilva

New member
hello
i think something is very strange... or i must have a really bad luck..

ive been using the random but it seems to go always for the same numbers, or sometimes it goes for those  nr/nrs more times...

ive tried the rand() from D&D warduke (random encouter)

#------------//----CURTIN-RANDOM-ELLE---//-----

anim follow3
@script
void self = getlocalvar("self");
if (frame == 1)
{
int  r = rand()%15+15;
if (r >= 0 && r < 10)
{
setglobalvar ("ellerad1", 1);
}
else if (r >= 10 && r < 20)
{
setglobalvar ("ellerad1", 2);
}
else if (r >= 20)
{
setglobalvar ("ellerad1", 3);
}
}
@end_script
loop 1
delay 12
offset 30 70
bbox 0 0 0 0
frame data/bgs/99gclub/may/empty.gif
frame data/bgs/99gclub/may/empty.gif
frame data/bgs/99gclub/may/empty.gif

#------------//----CURTIN-DRESS-RANDOM---//-----

anim follow4
@script
void self = getlocalvar("self");
if (frame == 1)
{
int  r = rand()%15 + 15;
if (r >= 0 && r < 5)
{
setglobalvar ("elledrss1", 1);
}
else if (r >= 5 && r < 10)
{
setglobalvar ("elledrss1", 2);
}
else if (r >= 15 && r < 20)
{
setglobalvar ("elledrss1", 3);
}
else if (r >= 20 && r < 25)
{
setglobalvar ("elledrss1", 4);
}
else if (r >= 25 )
{
setglobalvar ("elledrss1", 5);
}
}
@end_script
loop 1
delay 20
offset 30 70
frame data/bgs/99gclub/may/empty.gif
frame data/bgs/99gclub/may/empty.gif
frame data/bgs/99gclub/may/empty.gif

but i think the random has something to do with with the time in the level...
the random numbers above are being used by an npc that talks to the player....
has soon has i enter the level i always run towards that npc to talk to him it should take me about 3 seconds before i reach him... so i always get the same random number depending on openbor elapsetime i think ?

are the randoms above correct ?
#------------//----CURTIN-RANDOM-ELLE---//-----
int  r = rand()%15+15;  //----3 options

#------------//----CURTIN-DRESS-RANDOM---//-----
int  r = rand()%15 + 15; //--5 options



''''''''''''''''''''''''''''''''''''''___««««««««««««««««
thanks...
iam on a very old laptop with a very weak internet connection... this is the only way i can reply most webpages bottuns arent working...
whites dragon random seems a good option... ie already finished the level and moved on.. now i know how the random works... but i it still looks like to me the rad()10 «««-9««+9 goes for the +9 more times... ive mode those 3 cups thing were you have 3 cups with an item inside then the cups move really fast and the player has to find the item when they stop... and middle cup was going to the left side more time times
i had to made .... int r = rand()%10+5;  «««« to get him to go left« right the same times

«««««««««««««««««««««««««««««««««««««««««««««««««««

//---------------------------move---------left-790--//---middle-940---//---right-1090-------------------------------

    if ( Ani == openborconstant("ANI_FOLLOW20"))
{
            void frame = getentityproperty(self,"animpos");
    int pch2 = loadsample("data/sounds/cup.wav");
    int x = getentityproperty(self,"x");
    int cupmv = getglobalvar ("mv1");
    int cupmv2 = getglobalvar ("mv2");
    int cupmv3 = getglobalvar ("mv3");



int r = rand()%10+5;

if (x==940)
{
changeentityproperty(self, "velocity", 0, 0);

if (r >= 5 && cupmv3 == 3)
{
setglobalvar ("mv1", 1);
changeentityproperty(self, "velocity", -3-aggro);
setglobalvar ("mv3", 0);
playsample(openborconstant(pch2), 0, 100, 100, 100, 0);
}
else if (r < 5 && cupmv3 == 3)
{
setglobalvar ("mv2", 2);
changeentityproperty(self, "velocity", 3+aggro);
setglobalvar ("mv3", 0);
playsample(openborconstant(pch2), 0, 100, 100, 100, 0);
}
    int cupmv = getglobalvar ("mv1");
}
if (cupmv == 1 && x <= 790 )
{
setglobalvar ("mv3", 3);
changeentityproperty(self, "velocity", 3+aggro);
setglobalvar ("mv1", 0);
}
else if (x <= 790 )
{
setglobalvar ("mv3", 3);
changeentityproperty(self, "velocity", 0, 0);
}
    int cupmv = getglobalvar ("mv2");
if (cupmv2 == 2 && x >=  1090 )
{
setglobalvar ("mv3", 3);
changeentityproperty(self, "velocity", -3-aggro);
setglobalvar ("mv2", 0);
}
else if (x >=  1090 )
{
setglobalvar ("mv3", 3);
changeentityproperty(self, "velocity", 0, 0);
}
} //follow 20 end


«««««««
p.s. aggro equal entity aggression + or - for the cups to move faster if the player finds he item
 
Yes I think random is pseudo-random because it uses a seed or something, and if you try to use random in the exact same situation (memory wise) you'll get the same number.

I guess they are workarounds this (maybe using random with no purpose before using it with purpose) but I'll let those that know this better than me answer.
 
I feel random works in a strange way.

I have a stun anim triggered randomly when enemies fall then rise/get up.
If 2 or more enemies fall simultaneously random will be played the exact same way for all of them.
It can create strange scenes where you can see 5 or more enemies rising simultaneously then playin dizzy animation... ???

Again this is only observation, I have no general coding skills.
 
nedflandeurse said:
I feel random works in a strange way.

I have a stun anim triggered randomly when enemies fall then rise/get up.
If 2 or more enemies fall simultaneously random will be played the exact same way for all of them.
It can create strange scenes where you can see 5 or more enemies rising simultaneously then playin dizzy animation... ???

Again this is only observation, I have no general coding skills.

rand() can generate a negative num too..
WARNING that rand()%10 IS NOT a number between 0 and 9
but between -9 and 9
so add a selection:

int r = rand()%10;
if ( r < 0 ) r *= -1;

it gens a num between 0 and 9!

This is my func that gens a nums between x and y:
Code:
int rand_gen(int x, int y) {
    int num = 0;
    int r = rand();

    if (r < 0) r *= -1;
    num = x+(r%((y-x)+1));

    return num;
}
 
The random generator dates back to the original BOR written by Roel. It uses a fixed bitwise seed. The seed is updated each time random numbers are called for. Since the AI uses random and reacts to player interaction, YOU are the random seed generator.

This is a very clever, effective, and portable setup since not all consoles have a system clock and it is physically impossible for humans to provide input without some degree of randomness. It does however mean that until there has been some interaction with AI controlled entities the numbers returned won't be random at all.

Attempts to introduce clock seeds just made massive bugs. There are some workarounds you as an author can do though in order to seed from the player and get a random number.
 
Back
Top Bottom