Raised This Month: $ Target: $400
 0% 

Randomly choose item only once


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 07-09-2010 , 19:50   Randomly choose item only once
Reply With Quote #1

So lets say i have twenty items and i have to draw one and there is random chance for that.So far so good.But the thing is, that every item must be chosen once.And to clear things up this way there has to be twenty different draws with one different item.
SpeeDeeR is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-09-2010 , 20:43   Re: Randomly choose item only once
Reply With Quote #2

Quote:
Originally Posted by SpeeDeeR View Post
So lets say i have twenty items and i have to draw one and there is random chance for that.So far so good.But the thing is, that every item must be chosen once.And to clear things up this way there has to be twenty different draws with one different item.
This will give you a random number ranging from 1-20, with each only being returned once. After the twentieth item is used\selected, the selected-numbers will be cleared and you will be able to obtain a new set of 1-20, again each being returned only once. I'm not sure if you were using 1-20 just for example purposes or if it is what you actually needed. Let me know and I can fix it.

PHP Code:
RandomNumber()
{
    static 
iSelected iRandom;
    
    if ( 
iSelected == 0x1FFFFE )
        
iSelected 0;
        
    for ( ;; )
    {
        
iRandom random_num20 );
        
        if ( !( 
iSelected & ( << iRandom ) ) )
        {
            
iSelected |= ( << iRandom );
            return 
iRandom;
        }
    }
    
    return 
0;

__________________

Last edited by Bugsy; 07-09-2010 at 20:52.
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:15.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode