Quote:
I was able to easily use the internal Python getrandom() function and add the function to the assembler. Here is the result :
Glad you found the assembler easy to modify (one of the reasons for switching to Python from TAWK). If what you did meets your needs, great!
I did play around a bit with the idea myself. Here's what I came up with so far (and only lightly tested so far).
I did use Python's random module:
Code:
from random import seed, randint
I added these two functions:
Code:
def fncRnd(lo, hi=None):
'''random integer in the range lo <= N <= hi'''
return ( True, randint(0, lo) if hi is None else randint(lo, hi) )
def fncSeed(val=None):
'''seed the random number generator'''
if val is None:
seed()
val = randint( 0, 2^31 )
else:
seed( val )
return( True, val )
I wanted SEED() to return the value it used as a seed in case someone wanted to save it and generate the same sequence later. Not really possible with Python's internal SEED() function, which doesn't return anything at all. If it is not given a value, it uses the internal clock or whatever else the hardware provides, but won't tell you what the actual value was. So I had to cheat a bit and generate one random value before I could return that value (not quite tested yet, but I think it'll work).
In the function dispatch table I connected the names to the functions:
Code:
'RND': ( fncRnd, 1, 2, 'nn2n' ),
'ROOTFILE$': (fncRfn, 0, 0, '2s' ),
'SEED': (fncSeed, 0, 1, 'n2n' ),
The table doesn't actually have to be in alphabetic order, but I find it easier to modify if it is...
If all goes well, these will be in the next release (currently trying to add 6800 and 6803 instruction sets). Though I think I need to see what happens for something like RND(63, -1)...