That is true, and its true in the Java code too, as the rand.nextInt() will always return an integer which must be positive.
Jim -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Benjaminsen Sent: 03 November 2006 13:42 To: Flashcoders mailing list Subject: Re: [Flashcoders] OT conver java code to flash Hi Paul Actually Math.random always return a positive number between 0 and 1 so you can further simplify to: if (Math.random() < .5) { bestXPos = i; } /Chris Paul Steven wrote: > Thanks Jim. I was curious as I have seen Math.rand() mentioned on various > flash forums and even on one of the macromedia / adobe live docs page. But I > guess these were just mistakes by people familiar with Java. > > For my particular need, I have just simplified it to > > if (Math.abs(Math.random()) < (0.5)) { > bestXPos = i; > } > > As I was not sure what exactly the Java code did but realised it simply > wanted to implement making a random choice. > > Thanks > > Paul > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of jim > Sent: 03 November 2006 13:17 > To: 'Flashcoders mailing list' > Subject: RE: [Flashcoders] OT conver java code to flash > > It is Math.random() sorry. The Math.random() function returns a number > between 1 & 0. The Java function that you are using returns a random integer > or whole number, I don think there is an upper bound to it. > > The rest of your function is getting the modulus of the random number which > in fact is setting the upper bound to 10000. > > So to get the same sort of function you will need to set what upper bound > you want, I will use 10000 for now. I havnt tested this but it should give a > similar result. > > var intUpperBound :Number = 10000; > > if(goodness == bestWorst) > { > numOfEqual++; > > if(Math.abs(Math.random()*intUpperBound) < (intUpperBound / > numOfEqual)) { > > bestXPos = i; > > } > > } > > Hth > Jim > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Paul Steven > Sent: 02 November 2006 23:15 > To: 'Flashcoders mailing list' > Subject: RE: [Flashcoders] OT conver java code to flash > > Thanks Jim > > It is AS2, and the context is below. Btw what is the difference between > Math.rand() and Math.random()? > > // --------------------------------------------------- > // If two moves are equally good, make a random choice > // --------------------------------------------------- > > if (goodness == bestWorst) { > > numOfEqual++; > > if (Math.abs(rand.nextInt()) % 10000 < (10000 / numOfEqual)) { > > bestXPos = i; > > } > > } > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of jim > Sent: 02 November 2006 22:50 > To: 'Flashcoders mailing list' > Subject: RE: [Flashcoders] OT conver java code to flash > > Which version of actionscript? And in whats the context? > > The only thing that dosnt look like it will directlty port over is the > rand.nextInt() but you can use Math.rand() the rest is basic maths stuff you > can do in actionscript. > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Paul Steven > Sent: 02 November 2006 17:15 > To: 'Flashcoders mailing list' > Subject: [Flashcoders] OT conver java code to flash > > Not familiar with Java code but trying to rewrite some code in Flash. Anyone > convert this line to flash actionscript please > > if (Math.abs(rand.nextInt()) % 10000 < > (10000 / numOfEqual)) > bestXPos = i; > > Thanks > > Paul > > _______________________________________________ > 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 > > _______________________________________________ > 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 > > _______________________________________________ > 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 _______________________________________________ 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