This content has been marked as final.
Show 17 replies

1. Re: random odd number with in a range
MotionMaker Jan 12, 2007 6:26 AM (in response to MapleShilc)LE.text = LE +"1" does this work?
Try these
LE.text = LE.text + "1";
LE.text += "1";

2. Re: random odd number with in a range
MapleShilc Jan 12, 2007 6:29 AM (in response to MapleShilc)thanks for the hint, but im still stuck on getting a odd random number between 338 
3. Re: random odd number with in a range
mxc Jan 12, 2007 6:44 AM (in response to MapleShilc)This should work for you. Remember do not write number types as strings. That means no " " around numbers :) You can delete the trace actions when you see how the code works.
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max  min + 1)) + min;
return randomNum;
}
var n:Number = randRange(3, 38);
if (n % 2 == 0) {
trace("'" + n + "' is not an odd number.");
return;
} else {
gotoAndStop(n);
trace(n)
} 
4. random odd number with in a range
MapleShilc Jan 12, 2007 6:54 AM (in response to MapleShilc)omg thanks a lot .... but when a even number occurs, the mc just stops, i cant use
for (var i = 0; i < 2; i++)
to loop it... how can i loop it then? 
5. Re: random odd number with in a range
mxc Jan 12, 2007 6:58 AM (in response to MapleShilc)depends........what do you want it to do when an even number occurs? 
6. Re: random odd number with in a range
kglad Jan 12, 2007 8:32 AM (in response to MapleShilc)for your textfield you probably want to convert your textfield's text property (use the Number() function ) to a number before adding one to it or else you'll be performing string addition
to generate a random odd number between minNum and maxNum you can use:

7. Re: random odd number with in a range
MapleShilc Jan 12, 2007 8:33 AM (in response to MapleShilc)i use the number in
gotoandstop
so it jumps to a random frame 
8. Re: random odd number with in a range
kglad Jan 12, 2007 8:58 AM (in response to MapleShilc)is this thread still open? 
9. Re: random odd number with in a range
mxc Jan 12, 2007 9:11 AM (in response to MapleShilc)Hmm what do want the even numbers to do that is different to the odd ones?

10. Re: random odd number with in a range
kglad Jan 12, 2007 9:21 AM (in response to MapleShilc)he doesn't want even numbers. all the frames he wants to access have odd numbers. 
11. Re: random odd number with in a range
mxc Jan 12, 2007 9:36 AM (in response to MapleShilc)well I already posted the code for that 
12. Re: random odd number with in a range
Newsgroup_User Jan 12, 2007 3:01 PM (in response to MapleShilc)>>well I already posted the code for that
Not really. You posted code that might return an odd number... The OP was
looking for a function to return an odd number between a min and max... not
a function that _might_ return an odd number. Kglad posted the proper
function.

Dave 
Head Developer
www.blurredistinction.com
Adobe Community Expert
http://www.adobe.com/communities/experts/

13. random odd number with in a range
MapleShilc Jan 12, 2007 7:59 PM (in response to MapleShilc)the code i used:
function randomOddF(3, 38) {
var xmin = Math.floor((3)/2);
var xmax = Math.floor((381)/2);
ran = xmin+random(xmaxxmin+1);
return 2*ran+1;
}
if (randomOddF % 2 == 0) {
trace("'" + randomOddF + "' is not an odd number.");
return;
} else {
gotoAndStop(randomOddF);
trace(randomOddF)
}
i got these errors:
"**Error** Symbol=quiz, layer=CMD, frame=2:Line 1: Parameter name expected
function randomOddF(3, 38) {
**Error** Symbol=quiz, layer=CMD, frame=2:Line 6: Unexpected '}' encountered
}"
but if i used
function randRange(min:Number, max:Number):Number {
var randomNum:Number = Math.floor(Math.random() * (max  min + 1)) + min;
return randomNum;
}
var n:Number = randRange(3, 38);
if (n % 2 == 0) {
trace("'" + n + "' is not an odd number.");
return;
} else {
gotoAndStop(n);
trace(n)
}
it works, but it doesnt loop, so if a even number occurs, it stops... 
14. Re: random odd number with in a range
NSurveyor Jan 12, 2007 8:05 PM (in response to MapleShilc)You keep the function the way kglad has written it.
Then in your code, you would use:
var p:Number = randomOffF(3,38);
if (a == "18") {
gotoAndPlay(39);
} else {
gotoAndStop(p);
} 
15. Re: random odd number with in a range
NSurveyor Jan 12, 2007 8:09 PM (in response to MapleShilc)Whoops, meant randomOddF(3,38)...so your entire code should be
var p:Number = randomOddF(3,38);
if (a == "18") {
gotoAndPlay(39);
} else {
gotoAndStop(p);
}
function randomOddF(minNum, maxNum) {
var xmin = Math.floor((minNum)/2);
var xmax = Math.floor((maxNum1)/2);
ran = xmin+random(xmaxxmin+1);
return 2*ran+1;
} 
16. random odd number with in a range
MapleShilc Jan 13, 2007 11:21 AM (in response to MapleShilc)ohoh thanks >.< completely forgot about var p:Number
Thanks to all of you guys who helped, thanks a TON, =D 
17. Re: random odd number with in a range
kglad Jan 13, 2007 12:22 PM (in response to MapleShilc)you're welcome.