Terministic Random Number Generator Algorithm

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Terministic Random Number Generator Algorithm as PDF for free.

More details

  • Words: 383
  • Pages: 3
Simple Terministic Random Number generator To solve the problem of generating random number matching given format, Ex: XXYYZZ to provide 112233 or 665511 or 997788 1. 2. 3. 4. 5. 6.

Define sum = 0 Define previously selected random terms as an empty array (psrt) Read the pattern (p) Count number of terms (nt) Make array of unique terms only (ut) Loop through unique terms array (ut) a. For each element (e) do i. Create a copy from the original pa7ern , (p2) ii. Convert p2 to array of chars (p2c) iii. Loop through p2c • For each element (t) in p2c if t =e then p2c[t] = 1 else p2c[t]=0 iv. End loop in p2c v. Convert p2c to string convert then convert to integer (it) vi. Generate a random number (xrnd) from 0-9, check if it as string doesn't exists in psrt (if exists get another random) , append it to psrt vii. Sum = sum + (xrnd * it) 7. End loop in ut 8. Print sum

Sample 1. Define sum = 0

Sum = 0

2. Define previously selected random terms as an empty array (psrt)

Psrt = array

3. Read the pattern (p)

P = "ABCABC"

4. Count number of terms (nt)

nt = 3

5. Make array of unique terms only (ut)

ut = ["A","B","C"]

6. Loop through unique terms array (ut) a. For each element (e) do

e = "A"

e = "B"

e = "C"

v. Convert p2c to string convert then convert to integer (it) – decimal

it = 100100

it = 010010

it = 001001

i. Generate a random number (xrnd) from 0-9, check if it as string doesn't exists in psrt (if exists get another random) , append it to psrt

Xrnd = 8 psrt = [8]

Xrnd = 3 psrt = [8,3] += 030030

Xrnd = 9 psrt = [8,3,9] += 009009

i. Create a copy from the original pa7ern , (p2) ii. Convert p2 to array of chars (p2c) iii.

Loop through p2c •

For each element (t) in p2c if t =e then p2c[t] = 1 else p2c[t]=0

iv. End loop in p2c

vi. Sum = sum + (xrnd * it)

+= 800800

7. End loop in ut 8. Print sum

839839

Creator: Mohammad Nuaimat [email protected] 02 Feb 2009

Related Documents