The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Solved - Building an array with numbers 1-4 in random order.
palistov Offline
Posting Freak

Posts: 1,208
Threads: 67
Joined: Mar 2011
Reputation: 57
#1
Solved - Building an array with numbers 1-4 in random order.

Hey guys. Got a question for seasoned programmers. I'm trying to build an integer array with the numbers 1-4 in a random order. Having some trouble though. This particular bit of code doesn't have any syntax errors, but I'm worried about the semantics.

I ran the function with a debug message listing the order of the array it generates, but the debug message doesn't appear. I tried attaching a second debug message to at least let me know the function terminates, but apparently it just doesn't. I'm pretty sure it's because of the deeply nested while loop. Any suggestions on what I can do it get around this? Here's the code

PHP Code: (Select All)
void OnStart()
{
    
AddTimer(""2.0f"Test01CompileArray");
}
//pseudo callback I wrote to show how I run the function
void Test01CompileArray(string &in t)
{
    
UltDeathArray=CompileUltDeathArray();
    
//debug messages here
}
int[] UltDeathArray;
int[] CompileUltDeathArray()
{
    
int[] builder={0,0,0,0};
    
int temp;
    
int currIndex=0;
    for(
int i=1;i<=builder.length() ;i++)
    {
        
currIndex++;
        
temp=RandInt(1,4);
        for(
int j=1;j<=builder.length();j++)
        {
            while(
temp==builder[j-1]) temp=RandInt(1,4);
        }
        
builder[currIndex]=temp;
    }
    return 
builder;




(This post was last modified: 02-22-2012, 04:14 AM by palistov.)
02-22-2012, 03:30 AM
Find


Messages In This Thread
Solved - Building an array with numbers 1-4 in random order. - by palistov - 02-22-2012, 03:30 AM



Users browsing this thread: 1 Guest(s)