This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
Author Message
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 23 Dec 2003 04:27:50 pm    Post subject:

How do I make random numbers in 1-byte or 2-byte registers? The only random number generator I found is b_call(_Random) which only does a floating-point decimal 0 to 1. What I'm looking for is a way to get a random number [0,93] and, if possible, a random number gotten similarly to the basic randBin(.
Please help me! I've tried three Asm tutorials so far and none of them helped.
Back to top
Spyderbyte


Advanced Member


Joined: 29 May 2003
Posts: 372

Posted: 23 Dec 2003 04:52:20 pm    Post subject:

Well you've probably already tried this, but couldn'nt you multiply the floating point by 93, and then round it to the nearest integer? As far as RandBin, just repeat the process as many times as you need.

Spyderbyte
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 23 Dec 2003 04:53:10 pm    Post subject:

How do I multiply it?

Edit: for RandBin(# trials, p(success), [# simulations]), I would need a way to make the random number closer to 1 in less or more cases. What I need it for is to increase the average height of buildings in each level of my game, while leaving the possible range of heights the same.


Last edited by Guest on 23 Dec 2003 05:04:30 pm; edited 1 time in total
Back to top
tr1p1ea


Elite


Joined: 03 Aug 2003
Posts: 870

Posted: 24 Dec 2003 04:53:05 am    Post subject:

What about ionRandom? You could just rip the routine (and give proper credit of course Smile).

Last edited by Guest on 24 Dec 2003 04:53:29 am; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 24 Dec 2003 12:36:46 pm    Post subject:

I have an idea. There is an address in memory that stores the random number seed, about 8 bytes long. b_call(_Random) changes that to a new random number. If I want to make a random number 0..93, could I just load one of those bytes into a, then do and 93?

Edit: That would work but not well. There turn out to be some combinations you can't get. How about this?

93 = 63+15+15

Code:
RandSeed .equ SomeMemoryAddress
ld a, (RandSeed)
and 63
ld e,a;e=result
ld a, (RandSeed + 1)
and 15
add e
ld e,a
ld a, (RandSeed + 2)
and 15
add e
ld e,a

Would this work?


Last edited by Guest on 24 Dec 2003 01:01:02 pm; edited 1 time in total
Back to top
Adm.Wiggin
aka Tianon


Know-It-All


Joined: 02 Jun 2003
Posts: 1874

Posted: 24 Dec 2003 09:37:59 pm    Post subject:

why dont you use ionRandom? it does that, except more professionally, and no bcalls! Razz
Back to top
tr1p1ea


Elite


Joined: 03 Aug 2003
Posts: 870

Posted: 29 Dec 2003 10:36:33 pm    Post subject:

Try this: http://zilog.sh.cvut.cz/~baze/misc/z80bits.html#3 ...
Back to top
GuillaumeH


Newbie


Joined: 25 Oct 2003
Posts: 13

Posted: 30 Dec 2003 10:09:11 am    Post subject:

Yes, it is the routine used in Venus, I was about to post it when I saw tr1p1ea's post Wink
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 31 Dec 2003 07:16:11 pm    Post subject:

A random number 0..255 is easy to get. What I want to know is how to convert it to a different range.

I figured out how to do it though. It is not completely random (only 1/3 of the numbers is possible) but the numbers are evenly spread out over the range. What I did was

Code:
;Use some routine to get a random number 0..255
and 31;31 = %00011111 so this could be anything 0..31 w/ equal probability.
ld e,a;this will
add a,a;multiply a
add a,e;by three
Back to top
Job the GameQuitter


Member


Joined: 04 Jun 2003
Posts: 102

Posted: 05 Jan 2004 09:10:51 am    Post subject:

That's "simple": load the randomly generated number into E, load 0 into D and HL, then ADD HL,DE n times, where n=range. At the end LD A,H, and then 0=<A<n
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are UTC - 5 Hours

 

Advertisement