Author Topic: Axe Random Numbers  (Read 3417 times)

0 Members and 1 Guest are viewing this topic.

Offline Siphonic_Sugar

  • LV3 Member (Next: 100)
  • ***
  • Posts: 51
  • Rating: +0/-0
    • View Profile
Axe Random Numbers
« on: April 29, 2015, 06:36:43 pm »
Again, I have another post that will end up with someone telling me the answer to my problem and that answer will smack me in the face.  But anyway, I'm having trouble with using to rand function to help me create a random number from lets say 30 to 50.  I can't seem to get it to work, so could someone help me with this and give a little explanation because I can't find anything in the pdf thing for axe...
I'm on Codewalr.us now too, you should check it out.
<a href="https://codewalr.us"><img src="https://codewalr.us/other/cwaffiliate.png" /></a>

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Random Numbers
« Reply #1 on: April 29, 2015, 07:55:50 pm »
Axe really could use a command to generate an integer in a specified range. I think that's been on the to-do list for a long time, but getting it to work in an optimal fashion is a bit tricky. So it remains unimplemented...

Anyways, you can still generate a random integer in a certain range with rand. And you might kick yourself when you hear that, although the necessary information is a bit fractured, you can glean this technique from the Documentation.pdf file:
  • Page 13: This code block uses rand^88 and rand^54 to generate random X and Y coordinates, respectively. The sidebar mentions that "the easiest way to get random numbers is to take the modulus with X to get a random number between 0 and X-1." So the first snippet generates a random integer between 0 and 88-1=87, and the second generates a random integer between 0 and 54-1=53.
  • Page 18: The last code block uses rand^512-256 to generate a X random velocity. By following up the modulo operation with an addition/subtraction, this generates a random integer between 0-256=-256 and 512-1-256=255. In the general case: rand^A+B generates a random integer between B and A+B-1.

Offline Siphonic_Sugar

  • LV3 Member (Next: 100)
  • ***
  • Posts: 51
  • Rating: +0/-0
    • View Profile
Re: Axe Random Numbers
« Reply #2 on: April 29, 2015, 08:37:53 pm »
Okay, thanks for the help!  ;). By the way, where did you learn all of this stuff?  Years of experience?
I'm on Codewalr.us now too, you should check it out.
<a href="https://codewalr.us"><img src="https://codewalr.us/other/cwaffiliate.png" /></a>

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Random Numbers
« Reply #3 on: April 29, 2015, 09:29:00 pm »
Yep, years of experience. Looking at my post history, I've been using Axe for just over 5 years now. And when I started, I also asked a bunch of questions. So you're on a good track. :)

By the way, if you want to ask somewhat simple questions like these in the future (which are totally fine; good, even), I'd recommend asking in the Axe Q&A thread instead of making a topic for each one. Having one thread concentrated with questions and answers is a lot nicer than a bunch of individual topics that die off within a few posts. You can even just browse around the thread as a kind of grab-bag Axe documentation that covers practical information and techniques that may not be documented elsewhere.
« Last Edit: April 29, 2015, 09:32:36 pm by Runer112 »

Offline c4ooo

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 252
  • Rating: +10/-1
  • The impossible chemical compound.
    • View Profile
Re: Axe Random Numbers
« Reply #4 on: May 10, 2015, 07:25:55 pm »
Well it's sorta steeling someone's thread, but sense it's labeled "axe random numbers" and I need help with "axe random numbers" I guess ils do it anyway  :P
Basicly I need a seeded 16-bit rNdom number genarator. I tried using theLCG method ,but I can't get it to work for some resone :(
If any 1 has some axe or asm code to implement a LCG RNG, I would be grateful if he/she would share it :P
-German Kuznetsov
The impossible chemical compound.