Author Topic: Randon Integers  (Read 5071 times)

0 Members and 1 Guest are viewing this topic.

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Randon Integers
« 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.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Randon Integers
« Reply #1 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.
« Last Edit: July 20, 2010, 02:25:17 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Randon Integers
« Reply #2 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

Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Re: Randon Integers
« Reply #3 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.
« Last Edit: July 20, 2010, 02:39:35 pm by MRide »

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Randon Integers
« Reply #4 on: July 20, 2010, 02:40:22 pm »
What, was it supposed to be 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
« Last Edit: July 20, 2010, 02:41:04 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Randon Integers
« Reply #5 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)
« Last Edit: July 20, 2010, 02:42:59 pm by DJ Omnimaga »

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: Randon Integers
« Reply #6 on: July 20, 2010, 02:41:51 pm »
if you wanted a one digit integer, rand^10 should do the trick.


Offline MRide

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 711
  • Rating: +14/-0
  • You can't see this.
    • View Profile
Re: Randon Integers
« Reply #7 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.

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Randon Integers
« Reply #8 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.
« Last Edit: July 20, 2010, 02:58:02 pm by graphmastur »

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Randon Integers
« Reply #9 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
« Last Edit: July 20, 2010, 03:16:54 pm by calcdude84se »
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Randon Integers
« Reply #10 on: July 20, 2010, 04:37:56 pm »
Mhmm I see, thanks graph

Offline jnesselr

  • King Graphmastur
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2270
  • Rating: +81/-20
  • TAO == epic
    • View Profile
Re: Randon Integers
« Reply #11 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.