This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Black Ray
Posted Oct 24 - Read on Facebook

How to generate random numbers with specific chances?
Is there a way to do this gracefully?
for example:


Johannes Eckert

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

Noam Elbaz

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

Johannes Eckert

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:

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

Josh Puckett

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 1
else if i <= 2
return 2
else if i <= 4
return 3
else if i <= 7
return 4
else if i <= 10
return 5

Ezzat Chamudi

Black Ray did you try something like this?

Marc Krenn

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:

a...minimum, base
d...peak at

EDIT3: Also, could you give me the formula used in your chart?

Jordan Robert Dobson

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.

Dennis Kerzig

The bars in your graphic look pretty much like you want a normal distribution :) I found a pretty helpful javascript example of mapping a uniform distribution (Math.random()) to a normal one ( Then I had some fun creating a prototype demoing the "mean" and "standard derivation" values you can set. Hope it helps :) You can find it here: Preview here:

Marc Krenn

Here's a solution using normal distribution:

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.

Jordan Robert Dobson

If you want to control the percentage of each random choice here's one way:

Black Ray

Thanks all! This is actually what i was doing:

Read the entire post on Facebook