[vcf-midatlantic] Random numbers

Dan Roganti ragooman at gmail.com
Sat Apr 8 13:14:39 EDT 2017


On Sat, Apr 8, 2017 at 12:10 PM, Dan Roganti <ragooman at gmail.com> wrote:

>
>
> On Sat, Apr 8, 2017 at 11:55 AM, Dan Roganti <ragooman at gmail.com> wrote:
>
>>
>>
>> On Sat, Apr 8, 2017 at 11:45 AM, Dan Roganti <ragooman at gmail.com> wrote:
>>
>>> I bet all numbers look even to you when staying up till the break of
>>> dawn ;)
>>> I tried that line of code and still get a wide assortment of even and
>>> odd numbers
>>> As the others in this thread explained already, you're not doing
>>> anything wrong
>>>
>>> But one small thing,
>>> it's a good practice to out the RND(-1) at the beginning of every
>>> program you want random numbers
>>> So the RND generator gets seeded again right at the start each time you
>>> run that program,
>>> so the pseudo-rnd generator still tries to remain at least pseudo vs.
>>> being predictable ;)
>>> Dan
>>>
>>>
>>
>> ​Remember,
>> that step to seed the rnd generator is not perfect either​
>>>> ​, eg. RND(-32768) or whichever value​
>> ​if you use the same seed, guess what,
>> you get the same random numbers :)
>>
>>>>>>
>
>
> ​This is why you like to use something "random" to seed the rnd generator​
> Usually every computer has a free running counter,
> meaning it's constantly being updated in the background
> I don't recall at the moment where in the Apple ][ this is located, should
> be able to look it up again
> And you would PEEK this value into a variable
> and then use this value to Seed your RND Generator
> eg.
> 100 S=PEEK(address) *  -1
> 110 RND(S)
> The seeding process requires a negative number [S< 0] which is why you
> multiply by -1
> So then the seeding process is almost random too :)
> Dan
>
>
>


​ok found it, I dug up some old reference,​
Apple ][ has a free running counter at $4E,$4F
This is a 16bit counter, so that's why it's stored in 2 memory locations
,eg. 2 bytes
where $4E holds the lower byte half of the number, and $4F hold the upper
byte half of the number
This is used for the Keyboard Input routine in the Kernal Rom

But there's one slight glitch to work around, [on live hardware - some
emulators don't replicate this entirely]
I know you like to use RUN "filename" most of the times
But for some reason that counter is frozen at a fixed value, basically from
the time you Power On the computer.
So just this first, LOAD "filename", then RUN
And so the counter will be free running for as long as the computer is On

Then you just Peek those values at the beginning of your code to seed the
RND
And this is how you convert the Hex values into Decimal values, same as on
any computer
​S =RND ( -1 * ( PEEK(78) + 256 * PEEK(79) ) )​
http://paperity.org/p/18923593/cautions-regarding-random-number-generation-on-the-apple-ii
Dan



More information about the vcf-midatlantic mailing list