How to generate random numbers with specific chances?Is there a way to do this gracefully?for example:
Here's a half-ass approach if you want to skew responses, in a very simple examples
Utils.randomChoice [true,false]has equal chances to be true or false
Utils.randomChoice [true,true,false]has a 1/3 chance to be true
so I'm sure you could create an array that is skewed.But that sounds really tacky
If you know the general shake off the curve like generally going up then you can add on the random number between next five and positive five. So it will generally go up but will still have the randomness
I was going around on stackoverflow, and there are some answers, but they are probably not want you want. I just spent a couple of minutes playing around with something. Here are the results: http://share.framerjs.com/tztuguhyu4p7/
Don't know how useful this is to you.I definetly could not find out how to skew to a particular number within a given range
Most interesting question I've seen in a while :) The array is a brute force approach, or you could do something like this:
i = Utils.randomNumber(0, 100)if i <= 1 return 1else if i <= 2 return 2else if i <= 4 return 3else if i <= 7 return 4else if i <= 10 return 5...
Black Ray did you try something like this?
After re-reading your post, I'm pretty sure this is NOT what you were looking for but I'll give it another try tomorrow. :)
EDIT: But at least it's fun to play around with :D
EDIT2: Can you give a me better idea of what it should the solution should like in the end? For example:
Utils.randomNumberND(a,b,c,d)a...minimum, baseb...maximum,amplitudec...wavelengthd...peak at
EDIT3: Also, could you give me the formula used in your chart?
Yeah I would populate an array 100 times with your values and set each value to a fraction of that 100 hundred.
data = ["blue", "red", "yellow"]count = [70, 20, 10]colors = 
for color, index in data_ for i in [0...count[index]]__ colors.push color
So I think that's what @Ezzat was getting at.
Here's a solution using normal distribution:http://share.framerjs.com/8k3ifgp6fykn/
There is, however, a bug I haven't been able to fix yet. If you push 'mean' towards zero using a a negative value (e.g. -10), it will return the "min" value unproportionally often. Would be really cool if someone could help me out here. :)
Once this bug is squished, I'll wrap this function into a module.
If you want to control the percentage of each random choice here's one way: http://jrdn.io/1l1f441r1p10
Thanks all! This is actually what i was doing:https://github.com/RayPS/Framer-Module-LoremIpsumBlocks