Games, Random Numbers and Introduction to simple statistics - PowerPoint PPT Presentation

About This Presentation
Title:

Games, Random Numbers and Introduction to simple statistics

Description:

Title: Author: snmphost Last modified by: tsaiwn Created Date: 7/2/2000 4:21:46 AM Document presentation format: – PowerPoint PPT presentation

Number of Views:79
Avg rating:3.0/5.0
Slides: 59
Provided by: snmp
Category:

less

Transcript and Presenter's Notes

Title: Games, Random Numbers and Introduction to simple statistics


1
Games, Random NumbersandIntroduction to simple
statistics
??? tsaiwn_at_csie.nctu.edu.tw
  • PRNG
  • Pseudo Random Number Generator

2
Agenda
  • What is random number(??) ?
  • How the random numbers generated ?
  • rand( ) in C languages Linear Congruential
  • Why call Pseudo random ? (P???)
  • How to do true random ?
  • Application of Rrandom number ?
  • Other topics related to Random numbers
  • Introduction to simple statistics (????)

3
BATNUM game
  • http//www.atariarchives.org/basicgames/showpage.p
    hp?page14
  • An ancient game of two players
  • One pile of match sticks (or stones)
  • Takes turn to remove 1, maxTake
  • (??? 1, ??? maxTake)
  • ???????????? !
  • Winning strategy ??

Games ??? Random Number! Why?
4
Bulls and Cows Game
  • http//5ko.free.fr/en/bk.html
  • http//en.wikipedia.org/wiki/Bulls_and_cowsht
    tp//zh.wikipedia.org/zh-hant/E78C9CE695B0E
    5AD97http//boardgames.about.com/od/paperpencil
    /a/bulls_and_cows.htmhttp//pyva.net/eng/play/bk.
    html http//www.bullscows.com/index.phphttp//ww
    w.funmin.com/online-games/bulls-and-cows/index.php

Games ??? Random Number! Why?
5
NIM Game
  • http//en.wikipedia.org/wiki/Nim
  • Nim is a two-player mathematical game of strategy
    in which players take turns removing objects from
    distinct heaps. On each turn, a player must
    remove at least one object, and may remove any
    number of objects provided they all come from the
    same heap.
  • ???????????? !
  • Winning strategy ??

Games ??? Random Number! Why?
6
What is random number ?
  • Sequence of independent random numbers with a
    specified distribution such as uniform
    distribution (equally probable)
  • Actually, the sequence generated is not random,
    but it appears to be. Sequences generated in a
    deterministic way are usually called
    Pseudo-Random sequences.

?? http//www.gnu.org/software/gsl/manual/gsl-re
f_19.html
Normal distribution? exponential, gamma, Poisson,

7
Turbo C ? rand( )?srand( )
Pseudo random number
ltstdlib.hgt
  • define RAND_MAX 0x7fffu
  • static unsigned long seed0
  • int rand( )
  • seed seed 1103515245 12345
  • return seed (RAND_MAX1)
  • void srand(int newseed)
  • seed newseed

static global ?????KR??4.6?
??15? 1?binary
static ???file??function ???? seed
?? C ??? rand( ) ????? Normal Distribution!
8
Unix ? gcc ? rand( )?srand( )
Pseudo random number
ltstdlib.hgt
  • define RAND_MAX 0x7fffffffu
  • static unsigned long seed0
  • int rand( )
  • seed seed 1103515245 12345
  • return seed (RAND_MAX1)
  • void srand(int newseed)
  • seed newseed

static global ?????KR??4.6?
??31? 1?binary
Pseudo random number
?? Dev-Cpp ? gcc ???? 16 bits!
?? C ??? rand( ) ????? Normal Distribution!
9
Random Number Generating Algorithms
  • Linear Congruential Generators
  • Simple way to generate pseudo-random numbers
  • Easily cracked
  • Produce finite sequences of numbers
  • Each number is tied to the others
  • Some sequences of numbers will not ever be
    generated
  • Cryptographic random number generators
  • Entropy sensors (i.e., extracted randomness)

10
Linear Congruential Generator (LCG) for Uniform
Random Digits
  • Preferred method begin with a seed, x0, and
    successively generate the next pseudo-random
    number by xi1 (axi c) mod m, for i
    0,1,2, where
  • m is the largest prime less than largest integer
    computer can store
  • a is relatively prime to m
  • c is arbitrary
  • Let A be largest integer less than A
    (????????),
  • then N mod m N N/TT
  • Accept LCG with m, a, and c which passes tests
    which are also passed by know uniform digits

mod ?C/C/Java ?
11
The use of random numbers
1. Simulation 2. Recreation (game programming) 3.
Sampling 4. Numerical analysis 5. Decision making
randomness an essential part of optimal
strategies ( in the game theory) 6. Game
program, . . .
12
Uniform Distribution(???? )
  • ? ????????

13
Normal Distribution (???? )
14
Standard Normal Distribution(??????)
  • N(0, 1)
  • ??? 0
  • ??? 1

15
????(the Normal Distribution)
  • ?????,???????????????????????,?????????????????,?
    ???????????????????
  • ? X ???????,?? X N(?,?2)?
  • ???? ? ???,?2 ?????

?????????????(median)????(mode)????
?? C ??? rand( ) ????? Normal Distribution!
16
Central Limit Theorem (CLT)(?????? )
  • ??????? n ??,? n ??????????(independent and
    identically distributed, I.I.D.)?????(Random
    variable)????????????

????n?30?, ????????
17
??? C ??????????
  • include ltstdlib.hgt
  • double randNormal( ) // ?????????
  • int i
  • double ans 0.0
  • for(i1 ilt12 i) ans ans rand(
    )/(1.0RAND_MAX)return ans - 6.0 // N(0,
    1)

???? N(x, std2) ?
18
Summary
  • Pseudo-Random Number Generators(PRNG) depend
    solely on a seed, which determines the entire
    sequence of numbers returned.
  • How to get true random ? ? change random seed
  • How random is the seed?
  • Process ID, UserID Bad Idea !
  • Current time srand( time(0) ) // good
  • If you use the time, maybe I can guess which
    seed you used (microsecond part might be
    difficult to guess, but is limited)

19
Introduction to simple Statistics
  • ???
  • tsaiwn_at_csie.nctu.edu.tw

20
???? ???
  • ????????????96???????????????,????????????????????
    ?
  • ???????????????,????????,?????????????????????????
    ?????????

??????? 100???????? "??" ?
21
2010?????????
  • ????????????????,?????????????????,?????50???,?
    ????32?????????????????????????????,???1960??
    ????
  • ?????????,???????????,??????????????,????11?23?
    ??,????1273?,?95??????,??? 2.75?????

Sampling ??
22
2005?????????
??????????????????
??????????????????,????????,???????1103???,?95???
???,?????2.95???
? ?????????
??????, ????????????
23
2009????????
??????????/??????
?????????????????????,???????????????????????????
?????2009?11?10??11?????,?????932???????????,
??262?????????????????,???????3.2?????????????????
?????????????,???????????
24
2008???? ????
??????????????????????????????? ???????20??????
???,??????,?????2008?1?12???????,1?13??16???6??1
0???,??1054?????,?95??????,?????3?
25
2006?10??????????
???????2006/9/27?9/28,????????????,????1112???????
????????????????????,?????2.9???
26
2005??????????
  • ??TVBS?11?21?22????????,?????????????????48,?????
    ????????27?????
  • ??????????,??????????????????(BLOG)???,?????????
    ??,??2????,???????4?????
  • ?????TVBS?????11?21??22??,?????1033?20????????,?95
    ?????,????????3.0?????

27
1936 Presidential Election and Poll

28
??1936???????
  • ??????????????????????????????
  • ??????????????
  • ??????,?1929??1933?????????????
  • ??????????????????The spender must go?
  • ???????????????? (deficit financing)????Balance
    the budget of the American people first?
  • ????????????????????
  • ???Literary Digest????????57?43?????
  • ?????????????????????
  • ????1916??,????????????????
  • ????????62?38?????????
  • ?????-???-??
  • ??Literary Digest??????????????,????????,???????56
    ?44?????
  • ?????????????,??????????56?44?????

29
Literary Digest???????
  • ?????????????,????????,????????????????????
  • ????????????????,????????
  • ???????
  • ????Literary Digest??????????????,???????????????
  • ??????????
  • ????????,?????????????,???20???,????????????(Land
    on),????????????????????

???????????
30
Sample size vs. error of estimation
  • When we use to construct a 95 confidence
    interval for ?, the bound on error of estimation
    is B
  • n
  • The estimated standard deviation of p is

31
???????????
  • 1-? Confidence Interval
  • B the bound on error of estimation
  • Using a conservative value of ? 0.5 in the
    formula for required sample size gives
  • n ?(1-?) 0.5(1-0.5)
    1067.11
  • Thus, n would need to be 1068 in order to
    estimate ? to within .03 with 95 confidence.

95??????,???????3???????
32
Consider this program
  • ?????????????????,??????????????
  • ??????????
  • n ?????????
  • Average ????
  • STD ? n ???????

?? ????????, ???????????????????, ??????????????!
33
Descriptive Statistics
  • Dispersion
  • Range
  • Standard deviation
  • Variance
  • N
  • Not P (inferential stats)
  • Distribution
  • frequency distribution
  • Histogram (???)
  • Central tendency
  • Mean
  • Median (???)
  • mode (??)

Dispersion ???????
Distribution ????? ??
Central tendency ???????
34
Statistics
  • Parameters (??????)
  • Mean (???) - the average of the data
  • Median (???) - the value of middle observation
  • Mode (??) - the value with greatest frequency
  • Standard Deviation (???) - measure of average
    deviation
  • Variance (???) - the square of standard deviation
  • Range (??) - ?? Max(B2B60) Min(B2B60)?

35
Mean and Variance
Population Mean / Sample Mean
Sample Variance
36
Standard Deviation
  • Variance describes the spread (variation) of that
    data around the mean.
  • Sample variance describes the variation of the
    estimates.
  • Standard deviation s is the square root of s2

????? sqrt (???) ??????????
37
Compute Variance without mean
Variance (??? ????/n) / n
From Wikipedia.org
38
The Central Limit Theorem
  • The probability distribution of sample means
    is a normal distribution
  • If infinite number of samples with n gt 30
    observations are drawn from the same population
    where X ??(µ,s), then

39
Central Limit Theorem (??????)
  • For a population with a mean and a variance
    , the sampling distribution of the means of
    all possible samples of size n generated from the
    population will be approximately normally
    distributed - with the mean of the sampling
    distribution equal to and the variance equal
    to assuming that the sample size is
    sufficiently large.

40
The Normal Distribution
  • Described by
  • (mean)
  • (standard deviation ???)
  • Variance ??? ??????
  • Write as N( , ) ? N( , 2)
  • Area under the curve is equal to 1
  • Standard Normal Distribution

41
Why is the Normal Distribution important?
  • It can be a good mathematical model for some
    distributions of real data
  • ACT Scores
  • Repeated careful measurements of the same
    quantity
  • It is a good approximation for different types of
    chance outcomes (like tossing a coin)
  • It is very useful distribution to use to model
    roughly symmetric distributions
  • Many statistical inference procedures are based
    on the normal distribution
  • Sampling Distributions are roughly normal (TBC)

42
Normal Distributions and the Standard Deviation
Normal Distribution Black line - Mean Red lines -
1 Std. Dev. from the mean (68.26
Interval) Green lines 2 Std. Dev. from the mean
(95.44 Interval) What about 3 Std. Dev. from
the mean?
95 Confidence interval 1.96 Std. Dev.
43
68-95-99.7 Rule for Normal Curves
68.26 of the observations fall within ? of the
mean ?
95.44 of the observations fall within 2? of the
mean ?
99.74 of the observations fall within 3? of the
mean ?
44
Notations
  • It is important to distinguish between empirical
    and theoretical distributions
  • Different notation for each distribution

45
Density function of Normal Distribution
  • The exact density curve for a particular normal
    distribution is described by giving its mean (?)
    and its standard deviation (?)
  • density at x f(x)

46
Confidence Intervals (CI) for µ,from a single
sample mean
47
Confidence Interval? (1/2)
  • ???????????????,??????(random number)?????,???????
    ??????X1,????X2,???n??,??X1?X2...Xn?n???,?n???????
    ,?????????? ???,????n????????,?????????????
  • ????????????????????(sample mean)??
  • ????????????Confidence Interval
    (????)?????(significance level)?

48
Confidence Interval? (2/2)
  • ????,?????????????????????????????,????????
  • ??????????????????(probability bound)?????????????
    ????c1????????c2,??????????1 a
    ,????????????????µ(sample mean)???c1?c2??????
  • Probability c1 lt µ lt c2 1 a

???(c1, c2)??????????(confidence
interval) a??????(significance
level) 100(1-a)??????(confidence
level),?????? 1-a??????(confidence coefficient)?
49
??????????????????
  • ????16??????393??????????????,
  • ???1033???????
  • ????????,???????????????????,?????????????????,???
    ??16??????????????(????)???
  • ?????????,?????????????????

50
Hypothesis Testing?????
  • The null hypothesis for the test is that all
    population means (level means) are the same.
    (H0)
  • The alternative hypothesis is that one or more
    population means differ from the others. (H1)

51
PRNG ????
  • ?? http//gogle.com ? PRNG ??
  • ANSI X9.17 PRNG
  • (PRNG Pseudo Random Number Generator)
  • Von Neumann ??? middle square method
  • Von Neumann architecture ?
  • PRNG in RC4 (RC4?? 802.11 ???????)
  • http//www.rsa.com
  • http//www.wisdom.weizmann.ac.il/itsik/RC4/rc4.ht
    ml
  • WEP RC4 Stream cipher

52
ANSI X9.17 PRNG
  • Use 3DES and a key K
  • Ti Ek(current timestamp)
  • outputi Ek(Ti ? seedi)
  • seedi1 Ek(Ti ? outputi)
  • Weaknesses
  • Only 64 bits are used for Ti
  • seedi1 can be easily predicted if state
    compromise

53
Jon von Neumann 1946 suggested the production of
random number using arithmetic operations of a
computer, "middle square", square a
previousrandom number and extract the middle
digits, Example generate 10-digit numbers,
was 5772156649, square 33317792380594909201t
he next number is 7923805949
Middle square
"middle square" has proved to be a comparatively
poor source of random numbers. If zero appear as
a number of the sequence, it will continually
perpetuate itself.
54
Von Neumann architecture (http//wikipedia.org/)
  • The term von Neumann architecture refers to a
    computer design model that uses a single storage
    structure to hold both programs and data. The
    term von Neumann machine can be used to describe
    such a computer, but that term has other meanings
    as well. The separation of storage from the
    processing unit is implicit in the von Neumann
    architecture.
  • The term "stored-program computer" is generally
    used to mean a computer of this design.

Von Neumann bottle neck ?
55
Seeding RC4
RC4 PRNG (1/2)
  • for(I 0 I lt 256 I)
  • SI I
  • for (I J 0 I lt 256 I)
  • j SI KI klen
  • SWAP(SI, SJ)
  • I J 0

56
RC4 PRNG (2/2)
  • rc4byte()
  • I
  • J SI
  • SWAP(SI, SJ)
  • return (S SI SJ )

Byte version
57
WEP RC4 ??? (http//rsa.com)
Random bit stream b
Plaintext bit stream p
Ciphertext bit stream c
?
XOR
Decryption works in the same way p c ? b
WEP Wired Equivalent Privacy
58
Games, Random NumbersandIntroduction to simple
statistics
  • ????
  • http//www.csie.nctu.edu.tw/tsaiwn/introcs/
  • http//gogle.com/
Write a Comment
User Comments (0)
About PowerShow.com