Page 1 of 1

min rand and max rand function, with special selections...

PostPosted: Wed Apr 18, 2007 8:24 pm
by Sgt. Sparky
EDIT:
I feel sorta stupid posting this,
you can do this alot more easily by just putting texNumber or myvariable = -100 + rand(100); or whatever other number. xD
or my variable or textNumber = - 100 + round(rand(100));
here is a min rand and max rand thingie with special select functions...
Code: Select all
void mrand(int mn, int mx, char s[255], char t[255])
{
    float R;
    int S;
 
    R = mn;
    if(strcmp(t, "Round") == 0)S = 1;
    if(strcmp(t, "Norm") == 0)S = 2;
    if(S == 0)sprintf(s, "you may only select Round or Norm, not '%s'.", t);
    if(S == 1)
    {
        R = mn + round(rand(mx));
        sprintf(s, "%f", R);
    }
    if(S == 2)
    {
        R = mn + rand(mx);
        sprintf(s, "%f", R);
    }
}

the first number(left to right) is the minimum it can be.
the second number is the maxumum it can be.
right after that you select where you want it to be printed,
just like strcpy.
there is still one more thing after that... put Round for it to be a round number, and put Norm for it to be any number.
here is an example code that you put for the number to be from -1000 to 1000 and be printed into the actors text:
Code: Select all
mrand(-1000, 1000, text, "Norm");

all you do is put the bigger code into global and name it somthing than add it.
then you put the smaller code into the event that you want it to select the random number. :D
enjoy!