Hey guys, I need to generate a function called "produce" that will return either "peach", "panana", or "papaya" based on their probabilities of 0.20, 0.35, and 0.45 respectively. This is what I have:
function x = produceA = 1e5;B = rand;C = ceil(A*B)if (1 <= C <= 20000) C = 'peach';elseif ( 20001 <= C <= 55000) C = 'panana';elseif (55001 <= C <= 100000) C = 'papaya';end x = C
For some reason, it only generates a return of "peach" no matter what the number is. It won't return panana or papaya when it's in their number range. Please help if you can. Thanks!
Best Answer