News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Ranom number generator

Started by ahmad, January 08, 2006, 03:50:15 AM

Previous topic - Next topic

ahmad

Hi,
I have a problem in getting procedure that genrate 16-bits number using LFSR techinque, if any body could please help me. I'm using Pentium 4 processor.
Thanks

dsouza123


.586
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\m32lib\masm32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
includelib \masm32\m32lib\masm32.lib

.data
  tap    dd  10000001b        ; 81h  2 taps, bits 7,0  best with an even count of taps
  init   dd  00110111b        ; 37h  any starting value but 0 is OK
                              ; output bit is shifted from bit 7 to bit 8
                              ; new bit 0 is odd parity of value of tap masked bits before shift
                              ; ex: value before shift AND tap, if odd parity, then x=1, else x=0
                              ; new value = (value after shift AND 255) plus x
  szAns      db  256 dup (0)  ; bit output of LFSR converted to ASCII 0s,1s string
                              ; max output bits 2^8 - 1 for 8-bit LFSR

  szCaption  db  "8-bit LFSR, tap 81h, init xxh", 0

.code
start:
  mov edx, 0
  mov ecx, 0
  mov edi, 0
  mov eax, init

  .repeat
    mov dl, al
    shl eax, 1
 
    add ah, 30h
    mov [edi+szAns], ah
    inc edi
 
    and edx, tap
    setpo cl
    add eax, ecx
    and eax, 255
  .until eax == init

  invoke MessageBox, NULL, addr szAns, addr szCaption, MB_OK

  invoke ExitProcess, NULL
end start

ahmad

Thank you Very Much
and I have tried for another implementaion for that procedure and I have the following result.
.DATA
SEED  DW 1000000000010110B ; Intialazation of the REG.
MASK DW 10001101B
;*********************(Random Number Generator)*************
RANDOM PROC NEAR
   PUSHA
   MOV CX,65535 ; To do the operation
   L1:
   MOV AX,SEED
   SHR SEED,1
   AND AX,MASK
   MOV BX,AX
   MOV AL,0
   MOV CX,16
   L2:RCL BX,1
   ADC AL,0 ;
   LOOP L2
   MOV NUMBEROFONES,AL
   AND NUMBEROFONES,1
   JZ DONE ;If it is ZERO then go to DONE to Display 
   OR SEED,8000H
DONE:   MOVZX EAX,SEED
   CALL DISPGEN ; this procedure for display the number
   CALL NEWLINE; procedure for each line
   LOOP L1
   POPA
   RET
RANDOM  ENDP

Mark Jones

Here's one of Agner Fog's routines bundeled with a console app for generating random datafiles up to 4GB. Also illustrates a way to buffer 512kb chunks to disk. ENT.exe included:


Entropy = 7.999858 bits per byte.

Optimum compression would reduce the size
of this 1234567 byte file by 0 percent.

Chi square distribution for 1234567 samples is 242.10, and randomly
would exceed this value 50.00 percent of the times.

Arithmetic mean value of data bytes is 127.4888 (127.5 = random).
Monte Carlo value for Pi is 3.142772440 (error 0.04 percent).
Serial correlation coefficient is 0.000317 (totally uncorrelated = 0.0).

[attachment deleted by admin]
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

Mark Jones

Has anyone tried the AMD Core Math Library yet? The CDECL library contains lots of maths of course plus some new random number functions. Apparently you need a redistribution license from AMD to include the library with your apps though... anyone do this yet? Curious what's involved.
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08

P1

Is this homework?

Regards,  P1  :8)

Mark Jones

Heck naw! :P Just curious. IF I ever get a college degree, it'll probably be in electronics. ::)
"To deny our impulses... foolish; to revel in them, chaos." MCJ 2003.08