Raised This Month: $32 Target: $400
 8% 

[CS:GO] Random number without duplication


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
boomix
Senior Member
Join Date: May 2015
Location: Latvia
Old 06-09-2015 , 03:50   [CS:GO] Random number without duplication
Reply With Quote #1

Hello!

I'm making plugin where I need to make randomizer that selects random round, but I don't want to select round that already has been in the current map. The problem is, that I can't think of randomizer that will not repeat numbers that already has been. I need randomizer that selects numbers without duplication (no repeat).

Best that I could think was this -

PHP Code:
    new RandomNumber;
    
RandomNumberGetRandomInt(025);

    if (
LastRandomNumber!= RandomNumber) {
        if (
KvJumpToKey(DBRandomNumber), false)) {
           
//code
        
}
    }
    
LastWeaponNumber Random
but this code still repeats numbers, it just doesn't repeat last number.

btw, I read somewhere that the function GetRandomInt is old and buggy, that I don't need to use it. Is it true?

Last edited by boomix; 06-09-2015 at 03:52.
boomix is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 06-09-2015 , 07:13   Re: [CS:GO] Random number without duplication
Reply With Quote #2

PHP Code:
int Numbers[26] = {-1};
int UpperBound 25;

void Reset()
{
    for (
int i 026i++)
    {
        
Numbers[i] = i;
    }
    
    
UpperBound 25;
}

int GetRandomNumber()
{
    if(
Numbers[0] == -|| UpperBound == 0)
    {
        
Reset();
    }
    
    
int rn GetRandomInt(0UpperBound);
    
int ret Numbers[rn];
    
    for (
int i rnUpperBound 1i++)
    {
        
Numbers[i] = Numbers[1];
    }
    
    
UpperBound--;
    
    return 
ret;

Miu is offline
boomix
Senior Member
Join Date: May 2015
Location: Latvia
Old 06-09-2015 , 09:01   Re: [CS:GO] Random number without duplication
Reply With Quote #3

Quote:
Originally Posted by Miu View Post
PHP Code:
int Numbers[26] = {-1};
int UpperBound 25;

void Reset()
{
    for (
int i 026i++)
    {
        
Numbers[i] = i;
    }
    
    
UpperBound 25;
}

int GetRandomNumber()
{
    if(
Numbers[0] == -|| UpperBound == 0)
    {
        
Reset();
    }
    
    
int rn GetRandomInt(0UpperBound);
    
int ret Numbers[rn];
    
    for (
int i rnUpperBound 1i++)
    {
        
Numbers[i] = Numbers[1];
    }
    
    
UpperBound--;
    
    return 
ret;

Thanks alot!
boomix 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 21:09.


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