Jump to content

random integer not same as last


ellestones
 Share

You are about to reply to a thread that has been inactive for 2167 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

sometimes we want a random integer not the same as the last one

integer rnd(integer mag)
{  
   return (integer)llFrand((float)mag);
}

integer rndNotSameAsLast(integer num, integer mag)
{
    return (num + 1 + rnd(mag - 1)) % mag; 
}

default
{
    state_entry()
    {
        integer m = 4;
        integer i = 0;
         llOwnerSay("..."); 
        // get the first one 
        integer this = rnd(m);
        llOwnerSay((string)i + " : " + (string)this); 
        // get some more        
        for (i = 1; i < 20; i++)
        {
            this = rndNotSameAsLast(this, m);
            llOwnerSay((string)i + " : " + (string)this);
        } 
    }
}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2167 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...