THIS OBJECT HAS BEEN UPGRADED (AGAIN)·- NEW VERSION ATTACHED (V1.2)
Here's an object that is of value when you need TRULY RANDOM numbers -- not just pseudo-random sequences.
This came from the desire to have the Propeller be able to generate real random numbers internally for the purpose of data encryption. It can be used for lots of applications, though. It achieves randomness by jittering·a·CTR PLL and recycling the jitter into a pseudo-random excitation sequence. A few days ago, I was resigned to the notion that there was no way, shy of external hardware, that the Propeller would be able to generate random numbers. This opens up a lot of doors now.
I tried lots of variations on the theory until I distilled down the essentials. The main loop is only six instructions:
entry·················· movi··· ctra,#%00001_111······· 'set ctra to internal pll mode, select x16 tap
······················· movi··· frqa,#$020············· 'set frqa to system clock frequency / 16
······················· movi··· vcfg,#$040············· 'set vcfg to discrete output, but with no pins
······················· mov···· vscl,#70··············· 'set vscl to 70 pixel clocks per waitvid
:loop·················· waitvid 0,0···················· 'do a waitvid -- waits a randomly-varying time
······················· add···· phsa,cnt··············· 'incorporate time into pseudo-random sequence
······················· test··· phsa,#%10111··· wc····· 'step pseudo-random sequence while affecting...
······················· rcr···· phsa,#1················ '...pll target phase -- generates random jitter
······················· wrlong· phsa,par··············· 'write random value back to spin variable
······················· jmp···· #:loop················· 'loop·····························
Post Edited (Chip Gracey (Parallax)) : 3/23/2007 7:01:27 PM GMT