Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: MRide on July 20, 2010, 02:18:41 pm

Title: Randon Integers
Post by: MRide on July 20, 2010, 02:18:41 pm
Is it possible to create a random integer in Axe?  You could multiply the rand command by a power of ten, but there is no ipart or int command either.
Title: Re: Randon Integers
Post by: calcdude84se on July 20, 2010, 02:24:16 pm
what do you mean?
the rand command returns a random integer between 0 and 65535.
If you want a random integer in 8.8 fixed point, then rand*256 will work.
Edit: for clarification, Axe has no built-in support for non-integers except 8.8 fixed point.
Title: Re: Randon Integers
Post by: DJ Omnimaga on July 20, 2010, 02:28:43 pm
Since Axe doesn't support decimals, random int command would be useless in Axe. If you do rand/100, for example, you get a random number from 0 to 327, since the decimals are automatically truncated. Usually, people just use the modulus command, though.

Btw you have the same avatar as Mighty Moose, I thought you were him for a second ;D
Title: Re: Randon Integers
Post by: MRide on July 20, 2010, 02:32:08 pm
sorry, I misread the documentation for axe.  then how would you randomly select a one digit integer?

EDIT: about the avatar, something weird happened when I tried to upload my own picture.  It took forever, then gave me this one instead.

EDIT 2: Never mind, I got it changed.
Title: Re: Randon Integers
Post by: calcdude84se on July 20, 2010, 02:40:22 pm
What, was it supposed to be http://www.belligerati.net/archives/klein.jpg (http://www.belligerati.net/archives/klein.jpg)

On topic, I assume you mean one digit w/respect to the decimal system. For that, you can just use rand^10, where ^ is modulus
Edit: Picture's kinda large, so I just linked it
Title: Re: Randon Integers
Post by: DJ Omnimaga on July 20, 2010, 02:40:38 pm
I think there is a size limit (both KB and resolution) for avatars, but I'm not sure anymore. It was to stop people from using 8 MB large pics, slowing down the forums.

To select a random integer you use do rand->VAR (example: rand->A). It will store a number from 0 to 65535 into variable A. If you do rand/10000->A, it will store a number from 0 to 6, although the rate at which you'll get 6 will be lower than the other numbers.

Btw, when using modulus, if for example you use ^3, won't you have like 1 chance out of 65535 to get 0 as result? I checked with this: http://calculator.sdsu.edu/calculator.php (I didn't felt like writing an axe program just for that right now)
Title: Re: Randon Integers
Post by: nemo on July 20, 2010, 02:41:51 pm
if you wanted a one digit integer, rand^10 should do the trick.
Title: Re: Randon Integers
Post by: MRide on July 20, 2010, 02:44:54 pm
I think the problem was the original picture I tried to upload was meant to be a wallpaper for my desktop, so I just found this one.
Title: Re: Randon Integers
Post by: jnesselr on July 20, 2010, 02:55:34 pm
Btw, when using modulus, if for example you use ^3, won't you have like 1 chance out of 65535 to get 0 as result? I checked with this: http://calculator.sdsu.edu/calculator.php (I didn't felt like writing an axe program just for that right now)
No.  Any multiple of 3 will return 0 if done mod 3.  The basic idea is n=qd+r, where q is the quotient, r is the remainder, and d is the divisor.  If r=0, then that means n=qd, so d has to be a factor of n.  The same thing with n mod d.  If d is a factor of n, it will return 0.

Also, know something that might get confusing.  For any random number (produced by axe) n, n mod d produces numbers in the range of 0 to d-1.

[EDIT] Also, a random digit between m and n, where m>n, is (rand^(m-n+1)+n).  Note: The outer parenthesis are not necessary, and this is not tested, but should work.
Title: Re: Randon Integers
Post by: calcdude84se on July 20, 2010, 03:16:06 pm
They'd be necessary in certain contexts, like if you wanted to divide a number by that random integer. But yeah, if it's on its own line, then it's fine.
I also haven't tested it, but that code looks like it should work.
Edit: 555th post! I'm 5/6 of the way to being evil :P
Title: Re: Randon Integers
Post by: DJ Omnimaga on July 20, 2010, 04:37:56 pm
Mhmm I see, thanks graph
Title: Re: Randon Integers
Post by: jnesselr on July 20, 2010, 04:43:28 pm
Edit: 555th post! I'm 5/6 of the way to being evil :P
Congrats!

Mhmm I see, thanks graph
No problem.