0

Hi all,can enyone give a solution ,how to emplement random function,so it could randomly select numbers from the saved text file(grid) and output in matrix . What i try to do is:Create animation project,but would like color matrix as a background.What i did so far is came up to the idea using matrix as a background,now i need create an image in .....dat file and implement random function,so then i run the program this image would be in the matrix,color.So is the random function can do it? Any ideas are welcome.Regards.

3
Contributors
2
Replies
14
Views
3 Years
Discussion Span
Last Post by owenransen
0

Hard to tell for sure, but it seems to me that you want to randomize the background color. Simply make an array of the color choices and get a random index to choose the color. If you need help with using the rand() function here's a tutorial on it.

0

For random colors I use these two functions:

int RandomInt (const int Min, const int Max) 
/*
PURPOSE: To return a random number within or on the range handed
to us here.
*/
{
    int Num,Delta,RandNum ;

    RandNum = rand() ;
    /*
     * Put RandNum is between 0 and RAND_MAX-1 inclusive
     */
    if (RandNum == RAND_MAX) {
        RandNum = RAND_MAX - 1 ;
    }

    /*
     * Cover the correct magnitude. The interval is RAND_MAX/Delta
     * and so to cover a delta of 1 integer we add 1. Draw the
     * diagram!
     */
    Delta =  ((Max - Min) + 1) ;
    Num   = (RandNum * Delta) / RAND_MAX ;

    // Get Num to cover the correct range
    Num = Num + Min ;

    // Return the random int
    return (Num) ;
}

/*********************************************************************/

...and...

COLORREF RandomCol (void)
/*
PURPOSE: Create a random 24 bit colour
*/
{
    BYTE Red,Green,Blue ;

    Red   = (BYTE)(RandomInt (0,255)) ;
    Green = (BYTE)(RandomInt (0,255)) ;
    Blue  = (BYTE)(RandomInt (0,255)) ;
    return (RGB(Red,Green,Blue)) ;
}

The core is the call to rand()

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.