![]() |
Forum Index : Microcontroller and PC projects : Hardware generated random numbers
Page 1 of 2 ![]() ![]() |
|||||
Author | Message | ||||
Nimue![]() Guru ![]() Joined: 06/08/2020 Location: United KingdomPosts: 420 |
Picomite - 5.07.06 Got talking in class about random numbers and how "most" sources of random numbers are not really truly random and this led to a search for how its done in hardware. We looked at atmospheric detectors, Geiger counters, transistor in "avalanche breakdown" and oddly, lava lamps. Anyway, this led to sampling floating ADC input and checking the LSB. LSB coded, 0-4 = 1 and 5-9 = 1. Then rejecting the data if the LSB from both samples is the same. (von Neuman "whitening" I think this is called). 'USING FLOATING INPUTS, SAMPLE X2 ADCS AND CHECK THE LSB OF EACH SAMPLE. 'IF LSBS ARE THE SAME - REJECT THEM. IF DIFFERENT, USE LSB1 (ARBITARY) '0-4 = 0, 5-9 = 1 SAMPLES = 16 Dim FLOAT SAMP1(SAMPLES-1) Dim FLOAT SAMP2(SAMPLES-1) Dim BIT8(7) NO_BITS=50 ' EACH RANDOM SEQUENCE HAS 50 BITS NO_STREAMS = 10 ADC OPEN 1000,2 For Z = 0 To NO_STREAMS BITSTREAM$="" I=0 Do ADC START SAMP1(), SAMP2() 'GRAB SAMPLES - 16 SHOULD BE ENOUGH For Y = 0 To (SAMPLES)-1) YT1$ = Str$(SAMP1(Y)) YT2$ = Str$(SAMP2(Y)) 'EVALUATE THE LSB - SHOULD BE 12 DIGITS 'IF 12, SELECT IT. IF LESS THAT 12 'IT WAS 0, SO SET TO ZERO. '0-4 = 0, 5-9 = 1 Select Case Len(YT1$) Case 12 LSB1=Val(Right$(YT1$,1)) If LSB1 >4 Then LSB1 = 1 Else LSB1 = 0 EndIf Case Else LSB1=0 End Select Select Case Len(YT2$) Case 12 LSB2 = Val(Right$(YT2$,1)) If LSB2 >4 Then LSB2= 1 Else LSB2=0 EndIf Case Else LSB2=0 End Select 'IF THE LSBS ARE THE SAME - DO NOTHING 'IF LSBS ARE DIFFERENT, USE THE LSB1 'INCREMENT THE COUNTER If LSB1 <> LSB2 Then Inc BITSTREAM$, Str$(LSB1) I = I + 1 EndIf Next Y 'MOVE TO NEXT SAMPLES 'WE DONT KNOW THE EXACT LENGTH I FROM EACH LOOP Loop Until I > NO_BITS 'STOP WHEN MORE THAN ENOUGH BITS Print (Left$(BITSTREAM$,NO_BITS)) ' PRINT THE BITSTREAM Next Z Seems to work "well" -- posting here for words of wisdom / suggestions and general insight into how I could do this better. Would be interested into other "easy" to implement hardware solutions using the mite. Currently playing with an AM radio tuned between stations and using that as the ADC source instead of leaving it to float -- will compare the two. Cheers all Nimue -edited for grammar Edited 2023-02-06 03:13 by Nimue Entropy is not what it used to be |
||||
TimD Newbie ![]() Joined: 23/02/2021 Location: United KingdomPosts: 27 |
I did something similar years ago by just having several astable multivibrators, each running at high - but differing - frequencies, and each representing a bit of the random number to be read by the microcontroller. So using just a hex Schmidtt inverter IC (like 74LS14), 6 capacitors & 6 resistors attached to 6 GPIO inputs, it's then very simple on the software side to combine the 6 binary inputs into a 6-bit number. Not perfect obviously, but reasonable if your sampling is not too high frequency or regular. - Tim |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
Any of my programs that are supposed to give known results.... :( It goes with "Amplifiers oscillate, oscillators don't". :( Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
I seem to recall reading that one mechanism used on the ZX Spectrum for generating (non-)random numbers was simply to read bytes from a certain section of the ROM that was regarded as particularly "random". The time taken for the user's first input action to a program (keyboard, joystick, etc.) would determine which address in the ROM to start from. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Nimue![]() Guru ![]() Joined: 06/08/2020 Location: United KingdomPosts: 420 |
That's interesting -- I wonder if the Hobbit used that as it had some odd interpretations of "random". Cheers N Entropy is not what it used to be |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
"Thorin sings about gold" He may well have done, he drove me flippin' mad with his racket! Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
"Thorin sits down and starts singing about gold" How to get a blank look from 99% of any audience. Best wishes, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Bill.b![]() Senior Member ![]() Joined: 25/06/2011 Location: AustraliaPosts: 235 |
Bach in the old days before controller chips I used a white noise generator fed to a logic gate to create a random movements of a robot car. Bill In the interests of the environment, this post has been constructed entirely from recycled electrons. |
||||
DrifterNL![]() Regular Member ![]() Joined: 27/09/2018 Location: NetherlandsPosts: 58 |
Something I thought of years ago was using the contact bounce that mechanical contacts have when switching to produce a random number. https://www.instructables.com/4-Bit-True-Random-Number-Generator/ What you could try is having one port controlling a relay and connecting the contacts of the relay to a counting port. Edited 2023-02-07 11:47 by DrifterNL Floating Point Keeps Sinking Me! Back To Integer So I Don't Get Injured. |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
Noise diode->amplifier->shaper->divider = random pulses for you to time. Feed into a 8-bit shift register and read in parallel every now and again. Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
Many years ago I was involved in putting together a quotation for a project to replace the UK premium bond drawing system (ERNIE) and this was the solution we proposed. Prior to that they used a system based on radioactive decay. I don't know what was eventually chosen and they are now on the 5th generation of ERNIE Note to Nimue. Have you played with MATH(RAND) on the PicoMite? This uses the Mersenne Twister algorithm and is supposed to be much better than the C inbuilt function Edited 2023-02-07 19:53 by matherp |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
I think I first saw a similar idea used in an old copy of Practical Wireless or somewhere like that. IIRC a neon was used rather than a noise diode - or maybe several of them. It's a long time ago now and I have brain fade... Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
phil99![]() Guru ![]() Joined: 11/02/2018 Location: AustraliaPosts: 2642 |
A good noise diode is the base-emitter junction of any transistor. Reverse bias it through a 1M resistor from 12V or more. The breakdown voltage is usually 7 to 9V. |
||||
Nimue![]() Guru ![]() Joined: 06/08/2020 Location: United KingdomPosts: 420 |
Yes - and that was the route into all this. Asked how random is random and me digging a hole for myself. If I can muster a few interested students I might get them to capture a couple of 1000 points and "do some stats". Yet another rabbit hole I can ill afford ;-) Cheers N Entropy is not what it used to be |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10315 |
If you want a comparison, the Colour Maximite 2 has a true H/W random number generator which is used whenever you call RND |
||||
Nimue![]() Guru ![]() Joined: 06/08/2020 Location: United KingdomPosts: 420 |
Of course!! Time to fire it up.... ![]() Entropy is not what it used to be |
||||
Nimue![]() Guru ![]() Joined: 06/08/2020 Location: United KingdomPosts: 420 |
How much geek in one photo ;-) N Entropy is not what it used to be |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
That is true geekery in all its beauty. :) I've not seen one of those Matsui boxes for ages. Edited 2023-02-08 03:01 by Mixtel90 Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Nimue![]() Guru ![]() Joined: 06/08/2020 Location: United KingdomPosts: 420 |
I've not seen one of those Matsui boxes for ages. Not shown but the RF in is a great match for my Zeddy and Speccy. B&W of course! Another rabbit hole for the weeked. N Entropy is not what it used to be |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
I really approve of the little Tardis too. :) Mick Zilog Inside! nascom.info for Nascom & Gemini Preliminary MMBasic docs & my PCB designs |
||||
Page 1 of 2 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |