Excel functions
The following percentage are the occurence probability.
How do I represent these values in excel.
35% No one buys Coffee Zing
30% 1 person buys Coffee Zing
25% 2 person buys Coffee Zing
10% 3 person buys Coffee Zing
I tried it out: =IF(RAND()<=1-J13-J15-J16,1,IF(RAND()<=1-J13-J14-J16,2,IF(RAND()开发者_如何学Python<=1-J13-J14-J15,3,0)))
But I somehow feels its wrong. Any suggestion?
Let's say in Row 1, we have some headers (Random 0 1 2 3)
Then in Row 2, we'll put those chances ([blank] 35 30 25 10)
Then in Row 3, we conveniently sum up those chances:
B3=B2
C3=B3+C2
D3=C3+D2
E3=D3+E2
And let's put our random number in A3:
A3=Rand()*E3
Notice that I'm multiplying it by the total (100), because we're comparing it to whole numbers, rather than percentages represented by 0 to 1.
Row 3 will now look something like this: (30.32352 35 65 90 100)
We now check our random number against the values in Row 3, and stick the answer in A4:
=IF(A3<B3,B1,IF(A3<C3,C1,IF(A3<D3,D1,IF(A3<E3,E1))))
Note how it need not bother checking the final value, so you could have:
=IF(A3<B3,B1,IF(A3<C3,C1,IF(A3<D3,D1,E1)))
精彩评论