We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Excuse the newbieness but:
I need to distribute the numbers from a[30]={ABC...} in b[300] slots. let's say m=30, n=300. Usually we just do:
delta = m/n for (int c=0; c<=n; c++) { int ix= round(c*delta); b[c]=a[ix] }
so b={AAAAAAAAAABBBBBBBBBBCCCCCCCCCC...}
The thing is that the values are distributed evenly. I mean, if the actual distribution is {10,10,10,10,10,10,10,10,10} I need it now {15,12,11,10,7,10,11,12,15} or something like that ("slower" increment/decrement at the ends)
I'm making sense?
Thanks for any help!
Answers
@grumo I'm not sure I understand what distribution you want, but it sounds like you can either:
E.g.
Then loop through i<300, call myCurve(i), and save the result in your array. If you actually just need to return a (letter grade?) instead, just have myCurve return char letter.
Thanks jeremy! What could be the formula for a curve that goes like the distribution like this one: 18,11,7,4,2,1,0,1,2,4,7,11,18-? basically I need something like a inverted bell curve that cold be expressed in simple terms (not interested in too much detail, just something that gives bigger values at the beginning, shorter values in the middle and then bigger ones again at the end)
look at map
y= map(x,0,300,0,36);
y=y-18;
y=abs(y);
There is an easy way to approximate the normal distribution curve (bell curve) and that is simply to add 6 random number in the range -1 to +1 and divide by 6.
Try this sketch to see what I mean. Notice the map() function to shift the random normal value to the new range.
Thanks @quark ! The thing is that I need the values in a sequence, not random values in normal distribution..
Basically I have some values that I need to distribute in an Array. The final array could look like { AAAAAAABBBBBBCCCCDDEDDCCCCBBBBBBAAAAAAAA } --At the ends of the array the number of each values is bigger and then decreases towards the mean. Again, I just need something like an inverted bell curve that cold be expressed in simple terms (not interested in too much detail, just something that gives bigger values at the beginning, shorter values in the middle and then bigger ones again at the end)
Don't you like mine? Just for loop over it, and use the value as upper bound for a 2nd nested fot loop to insert A, B etc. in the right number into an Array or so
Hi @Chisir! I just tested and it works! Thanks a lot+ Any idea how to attenuate it or modify the curve?
Well, now it's 0 to 36 in map
Try 0 to 24 and adjust- 18 accordingly
@grumo for two general approaches in addition to @Chrisir 's
map()
, here are two implementations usingsin()
andrandomGaussian()
. Each function takes the number of values you want, and the scale (0-y range of values) and returns a u-shaped sorted list.great! I thought I could use sin(), this is fantastic. Thanks a lot!
@grumo -- glad it was helpful. For the sake of completeness I also added examples based on the @Chrisir and @quark solutions to the demo sketch.
Wow, really helpful and relevant. Renaming this discussion for proper indexing. Thanks @jeremydouglass