7 Replies Latest reply on Jan 31, 2009 7:29 AM by kglad

# synchronizing multiple return statements?

Earlier I was having difficulty with getting random numbers to appear in fraction form, and kglad and cbleech helped me out considerably. In the process of writing the fraction generator, I received a request to display the decimal version of the fractions (I know nothing about functions or C++) and modestly modified kglad's code as follows:

-------- modified fraction/decimal code----------------
function ranbot(x, m) {
var d:Number = Math.ceil(Math.random()* x);
var n:Number = Math.floor(Math.random()* d);
if(m == 1){return n+ "/" + d;}
if(m == 2){return n/d;}
}
---------------------------------------------------------------------------

there's a clear problem: the fractions and decimals don't match. (I honestly didn't think the decimal modification would work). Ideas?
• ###### 1. Re: synchronizing multiple return statements?
to get a decimal representation of the fraction - actually perform the operation eg. 5/10 = 0.5 = 50%
try:

• ###### 3. synchronizing multiple return statements?
whoops i see you 'did' do that - but what do you mean 'they don't match' - are you expecting that if you input the same value for x that they will be the same? that 'is' the point of the randomization of the method - they 'wont' be the same each time you run it.

edit: sorry kg lol - your out late ;)
• ###### 4. Re: synchronizing multiple return statements?
lol. you beat me. (but i think i solved the problem.)
• ###### 5. synchronizing multiple return statements?
btw - that's an awesome solution! sweet!

edit: lol - TOTALLY!! that's just too cool... i suck, kg rules... lol
• ###### 6. Re: synchronizing multiple return statements?
thank you kglad! I will begin experimenting with it asap.
• ###### 7. Re: synchronizing multiple return statements?
you're welcome.