Click here to Skip to main content
14,424,142 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: In the spirit of the upcoming holiday... Pin
Cornelius Henning23-Dec-17 3:15
professionalCornelius Henning23-Dec-17 3:15 
JokeA highly random number generator Pin
Nish Nishant22-Dec-17 11:00
sitebuilderNish Nishant22-Dec-17 11:00 
GeneralSample output Pin
Nish Nishant22-Dec-17 11:02
sitebuilderNish Nishant22-Dec-17 11:02 
GeneralRe: Sample output Pin
Marc Clifton22-Dec-17 11:23
communityengineerMarc Clifton22-Dec-17 11:23 
GeneralRe: Sample output Pin
Daniel Pfeffer23-Dec-17 6:52
professionalDaniel Pfeffer23-Dec-17 6:52 
GeneralRe: Sample output Pin
charlieg24-Dec-17 11:48
Membercharlieg24-Dec-17 11:48 
GeneralRe: A highly random number generator Pin
OriginalGriff22-Dec-17 12:06
communityengineerOriginalGriff22-Dec-17 12:06 
GeneralRe: A highly random number generator Pin
CodeWraith22-Dec-17 12:23
MemberCodeWraith22-Dec-17 12:23 
Ok, you asked for it Smile | :)

It's intended for an 8 bit processor and can be asembled for 8 bit random values or for 16 bit. When i tested it. it had a nice Gaussean bell curve distribution, so the random values are indeed random enough for noncritical applications.

; =========================================================================================
; Generates a 16 bit or 8 bit (pseudo) random number
;
; Parameters:
; RF		16 bit random return value
; RF.0		8 bit random return value
;
; Internal:
; RE		Pointer to random state
; RD.0		Loop counter
; =========================================================================================

GetRandom:			GLO  RE							; save registers RE and RD.0 on the stack
					STXD
					GHI  RE
					STXD
					GLO  RD
					STXD

					LDI  lo(RandomState)			; load the address of the random state
					PLO  RE
					LDI  hi(RandomState)
					PHI  RE

					IF RandomSize == 16
					LDI  10H						; set up the loop counter to shift 16 bits
					PLO  RD
					ELSE
					LDI  08H						; set up the loop counter to shift 8 bits
					PLO  RD
					ENDIF

GRA_ShiftLoop:		GLO  RF							; shift the value in RF
					SHL
					PLO  RF

					IF RandomSize == 16
					GHI  RF							; extend to 16 bits
					RSHL
					PHI  RF
					ENDIF

					LDN  RE							; shift random state
					SHL

					IF RandomSize == 16
					STR  RE							; extend to 16 bits
					INC  RE
					LDN  RE
					RSHL

					ENDIF

					BNF GRA_BitZero
GRA_BitOne:			XRI  0A7H						; XOR over the random state
					STR  RE

					IF RandomSize == 16
					DEC  RE							; extend to 16 bits
					LDN  RE
					XRI  03EH
					STR  RE
					ENDIF

					GLO  RF							; add the bit to RF
					ORI  01H
					PLO  RF
					LBR  GRA_TestLoop
GRA_BitZero:		XRI  035H						; XOR over the random state
					STR  RE

					IF RandomSize == 16
					DEC  RE							; extend to 16 bits
					LDN  RE
					XRI  07AH
					STR  RE	
					ENDIF

GRA_TestLoop:		DEC  RD							; loop until all bits have been shifted
					GLO  RD
					BNZ  GRA_ShiftLoop
					
					INC  R2							; restore registers RE and RD.0
					LDXA
					PLO  RD
					LDXA
					PHI  RE
					LDN  R2
					PLO  RE
					SEP  R5

;------------------------------------------------------------------------------------------


; =========================================================================================
; Data
; =========================================================================================

RandomState:		db 2 dup (?)

;------------------------------------------------------------------------------------------

I have lived with several Zen masters - all of them were cats.

GeneralRe: A highly random number generator Pin
Marc Clifton22-Dec-17 13:23
communityengineerMarc Clifton22-Dec-17 13:23 
GeneralRe: A highly random number generator Pin
Nish Nishant22-Dec-17 13:50
sitebuilderNish Nishant22-Dec-17 13:50 
GeneralRe: A highly random number generator Pin
CodeWraith22-Dec-17 15:42
MemberCodeWraith22-Dec-17 15:42 
GeneralRe: A highly random number generator Pin
Marc Clifton22-Dec-17 16:20
communityengineerMarc Clifton22-Dec-17 16:20 
GeneralRe: A highly random number generator Pin
CodeWraith22-Dec-17 17:59
MemberCodeWraith22-Dec-17 17:59 
GeneralRe: A highly random number generator Pin
Marc Clifton24-Dec-17 3:47
communityengineerMarc Clifton24-Dec-17 3:47 
GeneralRe: A highly random number generator Pin
Maximilien23-Dec-17 12:49
MemberMaximilien23-Dec-17 12:49 
GeneralRe: A highly random number generator Pin
CodeWraith24-Dec-17 7:34
MemberCodeWraith24-Dec-17 7:34 
GeneralRe: A highly random number generator Pin
CodeWraith22-Dec-17 16:18
MemberCodeWraith22-Dec-17 16:18 
PraiseRe: A highly random number generator Pin
kmoorevs22-Dec-17 17:34
Memberkmoorevs22-Dec-17 17:34 
GeneralRe: A highly random number generator Pin
Bassam Abdul-Baki2-Jan-18 6:00
professionalBassam Abdul-Baki2-Jan-18 6:00 
GeneralRe: A highly random number generator Pin
Nish Nishant2-Jan-18 6:03
sitebuilderNish Nishant2-Jan-18 6:03 
GeneralRe: A highly random number generator Pin
Bassam Abdul-Baki2-Jan-18 6:18
professionalBassam Abdul-Baki2-Jan-18 6:18 
GeneralRe: A highly random number generator Pin
Nish Nishant2-Jan-18 6:19
sitebuilderNish Nishant2-Jan-18 6:19 
QuestionHas anyone worked on a Core i9 CPU? Pin
Nish Nishant22-Dec-17 8:28
sitebuilderNish Nishant22-Dec-17 8:28 
GeneralRe: Has anyone worked on a Core i9 CPU? Pin
harold aptroot22-Dec-17 8:46
Memberharold aptroot22-Dec-17 8:46 
GeneralRe: Has anyone worked on a Core i9 CPU? Pin
Nish Nishant22-Dec-17 8:49
sitebuilderNish Nishant22-Dec-17 8:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.