RE: [Flashcoders] Random between, with sticklers
I thought of something. function randomRange( min, max, currNum):Number { if(Math.random()0.5){ max=currNum; }else{ min=currNum; } return Math.round(Math.random()*(max-min))+min; }; That's going to skew your function something chronic. No, what you need is this: function randomRange(min, max, curr) { var nNum = Math.round(Math.random() * (max-min-2) ) + min if (nNum=curr) {nNum+=2} return nNum } Danny ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Random between, with sticklers
Thats actually pretty good. Thanks for that :) I've added some additional logic to it, so I also don't get back a previously produced result too. Thanks :) - e. On 12/5/06, Danny Kodicek [EMAIL PROTECTED] wrote: I thought of something. function randomRange( min, max, currNum):Number { if(Math.random()0.5){ max=currNum; }else{ min=currNum; } return Math.round(Math.random()*(max-min))+min; }; That's going to skew your function something chronic. No, what you need is this: function randomRange(min, max, curr) { var nNum = Math.round(Math.random() * (max-min-2) ) + min if (nNum=curr) {nNum+=2} return nNum } Danny ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Random between, with sticklers
yup, you are correct. No point of setting two ranges, plus 1 or minus 1 is good enough. Thanks. On 12/5/06, Danny Kodicek [EMAIL PROTECTED] wrote: I thought of something. function randomRange( min, max, currNum):Number { if(Math.random()0.5){ max=currNum; }else{ min=currNum; } return Math.round(Math.random()*(max-min))+min; }; That's going to skew your function something chronic. No, what you need is this: function randomRange(min, max, curr) { var nNum = Math.round(Math.random() * (max-min-2) ) + min if (nNum=curr) {nNum+=2} return nNum } Danny ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- /* Bored, sometimes. */ ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
[Flashcoders] Random between, with sticklers
I'd like to get a random number between 2 values, with a stickler that it can't be a current value, and it can't be the current value +1 var nCurrentValue:Number = 1; function randomRange( min, max):Number { var nNum = Math.round(Math.random() * max) + min; return nNum; // Would like to add conditional: if nNum == nCurrentValue || nNum == nCurrentValue+1, get another random number until we get one thats okay... }; What is the best way of handling that? Using a while statement or something? I could use an interval, but that seems messy to me. - e. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] Random between, with sticklers
I thought of something. function randomRange( min, max, currNum):Number { if(Math.random()0.5){ max=currNum; }else{ min=currNum; } return Math.round(Math.random()*(max-min))+min; }; On 12/5/06, eric dolecki [EMAIL PROTECTED] wrote: I'd like to get a random number between 2 values, with a stickler that it can't be a current value, and it can't be the current value +1 var nCurrentValue:Number = 1; function randomRange( min, max):Number { var nNum = Math.round(Math.random() * max) + min; return nNum; // Would like to add conditional: if nNum == nCurrentValue || nNum == nCurrentValue+1, get another random number until we get one thats okay... }; What is the best way of handling that? Using a while statement or something? I could use an interval, but that seems messy to me. - e. ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- /* Bored, sometimes. */ ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com