Shop OBEX P1 Docs P2 Docs Learn Events
numbers using floating voltages — Parallax Forums

numbers using floating voltages

Special_KSpecial_K Posts: 162
edited 2006-10-26 19:38 in BASIC Stamp
Looking for a program I have seen before. It was code for the BS 2 that was a random number generator, it used the floating voltages of the unused pins to and a more (truer) random number response.

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-10-19 01:58
    You can tie an RC circuit to the pin, and use the RCTIME command. The least significant bits will be somewhat random and can be used to add real randomness to the Stamp's RANDOM operator. The bits are most random when the time constant is long and when you use poor components and expecially if you use poor wiring practices, Say, loop a long wire around and around, so that it will pick up AC hum and switching noise that adds to the capacitor voltage.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Special_KSpecial_K Posts: 162
    edited 2006-10-25 20:10
    Do you have a link to this circuit or code.
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-10-26 19:38
    Special_K said...
    Do you have a link to this circuit or code.

    It is just an RC circuit, like this one attached that has a time contant of RC=.1 second. The values are not critical so long as they have an RC value between 10 milliseconds and the RCtime maximum. The wiring is shown as curves to indicate that you should do it with long wires, wrapped around the edge of your circuit board & CPU for example. You could also include something like a reverse biased LED (cathode to the pin, p0 and anode to Vss) and that would make the circuit light sensitive as well. Here is code:

    chance_pin Pin 0
    lottery VAR word
    result VAR word
    
    DO
       HIGH chance_pin
       RCTIME chance_pin, 1, result
       RANDOM lottery   ' psuedorandom
       lottery=lottery+result   ' plus real radomizer
       DEBUG DEC lottery
    LOOP
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
    171 x 70 - 3K
Sign In or Register to comment.