The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
MCODE: random numbers
04-20-2019, 09:43 PM
Post: #1
MCODE: random numbers
While playing around with 41C MCODE, I've found a need for generating random numbers. Currently, I use the classic
Code:
ran = INT(seed * n) 
seed = FRC((seed * 9821) + .211327)
to get a random number between 1 <= ran <= n. I perform these calcs using the OS system calls (MP2-10, INTFRC), and because I'm using binary numbers (not BCD) I also have to convert to/from binary to bcd using OS system calls (BCDBIN and GENNUM).

I've recently been pondering the inefficiency of all that and wondering if there is a better way to implement random numbers in MCODE using binary directly. Of course, the 41C CPU doesn't have multiplication or division as part of it's repertoire, and I know that it can be simulated with shifting, repeated addition and repeated subtraction, but I haven't gone down those rabbit holes very far.

I was considering doing some form of XORSHIFT algorithm for the random number generation, and then (and this is the part I'm really unsure of) some smart version of shifting and subtraction to do the modulo portion, and wondering if anyone has experience or ideas about random number generation in binary, particularly without multiply/divide?

I'm considering this for "simulation" usage, so I don't need a super long period, or cryptographically safe algorithm.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
MCODE: random numbers - RobertM - 04-20-2019 09:43 PM
RE: MCODE: random numbers - John Keith - 04-20-2019, 10:12 PM
RE: MCODE: random numbers - RobertM - 04-20-2019, 10:40 PM
RE: MCODE: random numbers - Albert Chan - 04-21-2019, 01:35 AM
RE: MCODE: random numbers - RobertM - 04-21-2019, 02:03 AM
RE: MCODE: random numbers - Mark Power - 05-03-2019, 09:21 PM



User(s) browsing this thread: 2 Guest(s)