# Generate random colors from math3 distributions

**URL:** https://discourse.processing.org/t/generate-random-colors-from-math3-distributions/21027
**Category:** Coding Questions
**Created:** [May 18, 2020, 7:27pm UTC](https://discourse.processing.org/t/generate-random-colors-from-math3-distributions/21027 "2020-05-18T19:27:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dfamil](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@dfamil](https://discourse.processing.org/u/dfamil)
#### Post date: [May 18, 2020, 7:27pm UTC](https://discourse.processing.org/t/generate-random-colors-from-math3-distributions/21027/1 "2020-05-18T19:27:04Z")

</div>

If I use the random function everything works fine.  
if I try to map a generate a random distribution it only records the last number of the array. but the println is correct.  
vMin = min(valueYArray);  
vMax = max(valueYArray);  
for(int t =0; t \< valueYArray.length; t++)  
{  
valueY= valueYArray[t];  
float ran = random(255);  
s1.setValue(ran);  
randomOutputInt255=map(valueY,vMin,vMax,0,255);  
println( "randomOutputInt255= " + randomOutputInt255);  
this works:  
fill(ran,50,200);  
rect(10,600, 1000, 200);

```
     this doesn't work 
     randomOutputInt255=map(valueY,vMin,vMax,0,255);
      fill(rrandomOutputInt255,50,200); 
      rect(10,600, 1000, 200);

```

here is the console print out  
randomOutputInt255= 255.0  
randomOutputInt255= 255.0  
randomOutputInt255= 255.0  
randomOutputInt255= 255.0  
randomOutputInt255= 255.0  
randomOutputInt255= 5.5737934  
randomOutputInt255= 0.0  
randomOutputInt255= 125.409836  
randomOutputInt255= 205.53278  
randomOutputInt255= 244.54918  
randomOutputInt255= 252.2131

---

<div class="post-metadata">

### Author: ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)
#### Post date: [May 20, 2020, 1:37pm UTC](https://discourse.processing.org/t/generate-random-colors-from-math3-distributions/21027/2 "2020-05-20T13:37:12Z")

</div>

> [@dfamil](#):
>
> ```auto
> randomOutputInt255=map(valueY,vMin,vMax,0,255);
> fill(rrandomOutputInt255,50,200);
> 
> ```

There are two rr’s in the second variable name. The are not same variables

---

<div class="post-metadata">

### Author: ![dfamil](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@dfamil](https://discourse.processing.org/u/dfamil)
#### Post date: [May 20, 2020, 9:37pm UTC](https://discourse.processing.org/t/generate-random-colors-from-math3-distributions/21027/3 "2020-05-20T21:37:51Z")

</div>

thatgwas just a typo when i sent the message I did have fill(randomOutputInt255,50,200);

---

<div class="post-metadata">

### Author: ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)
#### Post date: [May 21, 2020, 3:50am UTC](https://discourse.processing.org/t/generate-random-colors-from-math3-distributions/21027/4 "2020-05-21T03:50:11Z")

</div>

Right. I don’t see anything wrong with the code. You haven’t included the definition of  
`randomOutputInt255`. What type is it? Print can handle a lot’s of different types, but fill needs float or anything that can be cast as float.

And what do you mean by doesn’t work? Is there an error message or results are not what you expect?
