# Thread: How to make random colors?

1. ## How to make random colors?

How to make a set of 4 random RGB colours? In freeglut or glut. Or opengl.

2. ## Re: How to make random colors?

Generate 4 random float values in [0, 1] and pass them to glColor4f().

3. ## Re: How to make random colors?

well it is not so straight forward.
I have 6 colors.
blue, green, yellow, light blue, white and red.
I want to create a set of 4 colors from them.

Code :
`colours array[6] = {sblue, sgreen, slblue, syellow, sred, swhite}`
;

I got this. All the members are the objects of my structure colours whose members are R, G, B.
How can I do it?
Code :
```struct colours
{
int red;
int green;
int blue;

}sblue, sgreen, slblue, syellow, sred, swhite;
//--------------------------------------------------------------------------------------------------------------------
int createrandomcolors()
{
sblue.red = 0; sblue.green = 0; sblue.blue = 255;
sgreen.red = 0; sgreen.green = 100; sgreen.blue = 0;
slblue.red= 0; slblue.green = 255; slblue.blue =255;
syellow.red =265; syellow.green = 140; syellow.blue = 0;
sred.red =1; sred.green = 0; sred.blue = 0;
swhite.red=1; swhite.green = 1; swhite.blue =1;
colours array[6] = {sblue, sgreen, slblue, syellow, sred, swhite};
}```

4. ## Re: How to make random colors?

So what you want to do is to pick 4 out of those colours at random? That was completely impossible to guess from your original post.

Just generate 4 random integers, to use as indices for an array of colours?

5. ## Re: How to make random colors?

Sorry about that. I suck at making posts.
could you please tell me in detail how to do that?

6. ## Re: How to make random colors?

Originally Posted by programmer17
could you please tell me in detail how to do that?
Ref: http://www.cplusplus.com/reference/c.../cstdlib/rand/

7. ## Re: How to make random colors?

Or you can use the built-in noise function in the shader language.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•