Jump to content

random integer not same as last


ellestones
 Share

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...