Random Writer

W
Shared by: dffhrtcv3
Categories
Tags
-
Stats
views:
2
posted:
9/30/2012
language:
Unknown
pages:
17
Document Sample
scope of work template
							Random Writer

    Joe Zachary
School of Computing
 University of Utah
            Random Writer
• Based on an idea by Claude Shannon (1948)
  popularized by A.K. Dewdney (1989)
• Generates random text based on the patterns
  in a source file
• Both fun and appropriate for CS 2 students
• Uses file input/output, string manipulation,
  dynamic linear data structures, and random
  number generation
                King James Bible
For every man putteth one and my mother: for them, to David
sent Samson, and a sacrifice.

Then went Samson down, and his father and his mother, to
Timnath, and came to the vineyards of Timnath: and,
behold, a young lion roared against him.


Now the ark; and treasures upon them: and, Who also in the
evil: so do your heart?
       King James Bible (Level 6)
For every man putteth one and my mother: for them, to David
sent Samson, and a sacrifice.

Then went Samson down, and his father and his mother, to
Timnath, and came to the vineyards of Timnath: and,
behold, a young lion roared against him.


Now the ark; and treasures upon them: and, Who also in the
evil: so do your heart?
                  Tom Sawyer
Huck started to act very intelligently on the back of his
pocket behind, as usual on Sundays.


He was always dressed fitten for drinking some old
empty hogsheads.


The men contemplated the treasure awhile in blissful
silence.
         Tom Sawyer (Level 8)
Huck started to act very intelligently on the back of his
pocket behind, as usual on Sundays.


He was always dressed fitten for drinking some old
empty hogsheads.


The men contemplated the treasure awhile in blissful
silence.
                           Hamlet

Ay me, what act, That roars so loud and thunders in the
index?


Worse that a rat? Dead for a ducat, drugs fit that I bid you not?


Leave heart; for to our lord, it we show him, but skin and he,
my lord, I have fat all not over thought, good my lord?
                 Hamlet (Level 5)

Ay me, what act, That roars so loud and thunders in the
index?


Worse that a rat? Dead for a ducat, drugs fit that I bid you not?


Leave heart; for to our lord, it we show him, but skin and he,
my lord, I have fat all not over thought, good my lord?
                   C++ Programs
int temp = A[0];
A[i-1] = A[j];
C[((A[j])>>(shift*8))& 0xff] + 1;

node *m_pTop;
m_pTop = pNext;
while (p!=end) res = 0;


int hash code = hash<string>()(key);
float A = (sqrt(5)-1)/2;
int index = floor(buckets * (hashcode * A - floor(hashcode * A)));
          C++ Programs (Level 7)
int temp = A[0];
A[i-1] = A[j];
C[((A[j])>>(shift*8))& 0xff] + 1;

node *m_pTop;
m_pTop = pNext;
while (p!=end) res = 0;


int hash code = hash<string>()(key);
float A = (sqrt(5)-1)/2;
int index = floor(buckets * (hashcode * A - floor(hashcode * A)));
                  Niftiness
• Not a toy: it slurps up entire books

• Defies expectations: it turns out to be both
  straightforward and educational

• Entertaining: I run a contest to find the
  funniest generated text
                   Level 0
The probability that c is the next character to be
produced equals the probability that c occurs in
the source file.

rla bsht eS ststofo hhfosdsdewno
oe wee h .mr ae irii ela iad o r
te u t mnyto onmalysnce, ifu en c
fDwn oee iteo
                    Level 1
Let s be the previously produced character. The
probability that c is the next character to be
produced equals the probability that c follows s in
the source text.

"Shand tucthiney m?" le ollds mind
Theybooure He, he s whit Pereg
lenigabo Jodind alllld ashanthe
ainofevids tre lin--p asto oun
                   Level K
Let seed be the previously produced k (4 in this
case) characters. The probability that c is the next
character to be produced equals the probability
that c follows seed in the source text.

Mr. Welshman, but him awoke, the
balmy shore. I'll give him that
he couple overy because in the
slated snufflindeed structure's
                 Algorithm
• Pick a random k-letter seed from the text
• Repeatedly:
  – Make a list of every character that follows the
    seed in the text
  – Randomly pick a character c from the text
  – Output c
  – Remove the first character from the seed and
    append c
       Example at Level 2
Seed: th
Text: We hold these truths to be
  self-evident: that all men
  are created equal; that they
List: [e, s, a, a, e]
Character: s (20% of the time)
New seed: hs
http://nifty.stanford.edu/

						
Related docs
Other docs by dffhrtcv3
losalamos06talk1.ppt - Rice University
Views: 1  |  Downloads: 0
Linkages
Views: 3  |  Downloads: 0
Linux Basics
Views: 1  |  Downloads: 0
Long Multiplication - dcbeagle.com
Views: 1  |  Downloads: 0
long - multiplication .ppt
Views: 1  |  Downloads: 0
Literature survey
Views: 1  |  Downloads: 0
LOGISTICS INTEGRATION
Views: 1  |  Downloads: 0
Literary Elements of “The Necklace”
Views: 0  |  Downloads: 0
Linguistica
Views: 3  |  Downloads: 0