Loading ...
Sorry, an error occurred while loading the content.

Re: Random # generator routine

Expand Messages
  • stonewerk2000
    Take a look at Ipso Facto Issue #4, page 23 - article entitled, Random Number Generator for the 1802 by B.J. Murphy. File pointer is in the Ipso Facto Folder
    Message 1 of 14 , Jun 30, 2011
    • 0 Attachment
      Take a look at Ipso Facto Issue #4, page 23 - article entitled, "Random Number Generator for the 1802" by B.J. Murphy.

      File pointer is in the Ipso Facto Folder in the Files section of this group.

      Danny
      KK4E

      --- In cosmacelf@yahoogroups.com, "whd_whd_whd" <whd_whd_whd@...> wrote:
      >
      > Does anyone know of a RNG routine I can look at/use?
      >
      > I looked at Tiny BASIC, and saw some references to RND, but didn't see
      > any actual code. (probably because I didn't look hard enough)
      >
      > I also looked around for something I could convert, from either actual
      > code or an algorithm, but didn't find anything that wouldn't be quite
      > a bit of work. (most of the stuff is 16/32 bit, or it is C code, and/or
      > it can be pretty complex -- I think I'm getting impatient in my old age)
      >
    • whd_whd_whd
      Thanks. Where is it?
      Message 2 of 14 , Jul 4, 2011
      • 0 Attachment
        Thanks. Where is it?

        --- In cosmacelf@yahoogroups.com, "sbirdasn" <sbirdasn@...> wrote:
        >
        >
        >
        > You will find working code in the files section inside my memory test program.
        >
        > It's a 2^16-1 sequence generator, though not really fast, it does cover all 65535 values except 0 before repeating. Not all PRNG's have full coverage, and not all have good distribution of values. I have no idea how good the 16-bit Multiply and Add version in TBASIC is, or compares to the one I uploaded.
        >
        > Don't expect miracles from the pattern generated, as it's pretty obvious that it's not really random if you peek at memory using pixie graphics to see the memory test program running. Interesting to watch the memory test pattern in operation, though.
        >
        > I've done about as much to optimize it as I can possibly think of, and have made the PRNG routine both register and stack-based for the working scratch pad during the generation process, and it made no difference as far as I can tell.
        >
        > You could make a fast hardware version with a handful of gates. It might even fit in a couple of medium sized PAL's or one larger one if you have the tools and feel ambitious enough.
        >
        > You might want to try it out just for kicks.
        >
        > Sbirdasn.
        >
      • Lee Hart
        ... A hardware pseudorandom number generator is very simple. It s just a shift register and a quad XOR gate. If you re building it in hardware, a true random
        Message 3 of 14 , Jul 4, 2011
        • 0 Attachment
          On 7/4/2011 1:44 PM, whd_whd_whd wrote:
          >> You could make a fast hardware version with a handful of gates. It
          >> might even fit in a couple of medium sized PAL's or one larger one
          >> if you have the tools and feel ambitious enough. You might want to
          >> try it out just for kicks.

          A hardware pseudorandom number generator is very simple. It's just a
          shift register and a quad XOR gate.

          If you're building it in hardware, a true random number generator is
          also easy. It's generally something like a noisy zener diode (zener
          operated at a few microamps) and a high-gain AC coupled opamp that slams
          rail-to-rail on the noise. It produces one bit, so you read it N times
          for an N-bit random number.

          --
          Lee A. Hart | Ring the bells that still can ring
          814 8th Ave N | Forget the perfect offering
          Sartell MN 56377 | There is a crack in everything
          leeahart earthlink.net | That's how the light gets in -- Leonard Cohen
        • RickC
          ... It s been a long time but isn t a hardware solution available with the proper programming for most implementations of 1802s? For instance as part of the
          Message 4 of 14 , Jul 4, 2011
          • 0 Attachment
            --- In cosmacelf@yahoogroups.com, Lee Hart <leeahart@...> wrote:
            >
            > On 7/4/2011 1:44 PM, whd_whd_whd wrote:
            > >> You could make a fast hardware version with a handful of gates. It
            > >> might even fit in a couple of medium sized PAL's or one larger one
            > >> if you have the tools and feel ambitious enough. You might want to
            > >> try it out just for kicks.
            >
            > A hardware pseudorandom number generator is very simple. It's just a
            > shift register and a quad XOR gate.
            >
            > If you're building it in hardware, a true random number generator is
            > also easy. It's generally something like a noisy zener diode (zener
            > operated at a few microamps) and a high-gain AC coupled opamp that slams
            > rail-to-rail on the noise. It produces one bit, so you read it N times
            > for an N-bit random number.
            >
            > --
            > Lee A. Hart | Ring the bells that still can ring
            > 814 8th Ave N | Forget the perfect offering
            > Sartell MN 56377 | There is a crack in everything
            > leeahart earthlink.net | That's how the light gets in -- Leonard Cohen
            >

            It's been a long time but isn't a hardware solution available with the proper programming for most implementations of 1802s? For instance as part of the interrupt routine for the 1861 you could increment a register and get a random seed that would be the ET from the time the display was enabled until the rand() routine was called. If the routine was to be called from BASIC, anything other then a tight loop would probably give pretty good results. It would change ~60 times/sec and go full range in 4 seconds if you just wanted to use it w/o any extra code.

            Rick
          • sbirdasn
            - In cosmacelf@yahoogroups.com, whd_whd_whd wrote: Thanks. Where is it? Answer-- Look in the Files - VIP sub folder. I was on vacation so
            Message 5 of 14 , Jul 12, 2011
            • 0 Attachment
              - In cosmacelf@yahoogroups.com, "whd_whd_whd" <whd_whd_whd@...> wrote:

              Thanks. Where is it?

              Answer--

              Look in the Files -> VIP sub folder.

              I was on vacation so I didn't look at my mail for more than a week...

              Keep in mind with all this software PNRG stuff is that there is limited processing power in the 1802, so the "incrementing counter during display refresh" and other simple math tricks are often used instead of this or similar algorithms.

              Another issue is masking/range issues. If you wanted, say, a six-sided die for a game, will you get a proper distribution of each value? And what if you use two die rolls, will the frequency of "doubles" be statistically correct? Doubles rolls, and repeated doubles rolls are pretty common in real life. Just play a couple of games of "Monopoly" (TM) to see that in action.

              I have not studied the behavior in detail of the memory test PRNG, but I do know that from a 16-bit perspective, it never yields the same number again until 2^16-1. What happens from a 3-bit perspective may still not look much like real world dice either unless "enhanced" with multiple calls and random samples in the resulting stream of PRN's or other tricks.

              Not all uses for PRNG's need to be "realistic", just unpredictable from the user's perspective.

              All for now.

              Sbirdasn.
            Your message has been successfully submitted and would be delivered to recipients shortly.