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.
PulsarScript
- 3 Contributors
- forum2 Replies
- 14 Views
- 4 Years Discussion Span
- comment Latest Post by owenransen
owenransen 14
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()