# create a random color from range.

Page 1 of 1

## 2 Replies - 189 Views - Last Post: 07 October 2012 - 04:25 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=294668&amp;s=469494a097c63ae804ab84f3a0c376d1&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

Reputation: 0
• Posts: 52
• Joined: 07-October 12

# create a random color from range.

Posted 07 October 2012 - 03:36 PM

I'm suppose to create a random color from the ranges:
0 <= red < 1.0
0 <= green < 1.0
0 <= blue < 1.0

Am I doing it right and if so is this the best way to do this?
```//Random Object color
float red   = (float) (Math.random() * (1.0));
float green = (float) (Math.random() * (1.0));
float blue  = (float) (Math.random() * (1.0));
Color color = new Color(red, green, blue);

```

Is This A Good Question/Topic? 0

## Replies To: create a random color from range.

### #2 jdavi134

Reputation: 42
• Posts: 225
• Joined: 26-October 11

## Re: create a random color from range.

Posted 07 October 2012 - 04:20 PM

Well your way does work, but the random method from the Math class already returns a value in the range 0=< Math.random() < 1

So adding the *1.0 isn't necessary.

Reputation: 0
• Posts: 52
• Joined: 07-October 12

## Re: create a random color from range.

Posted 07 October 2012 - 04:25 PM

Thank you.