lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


From: Luiz Henrique de Figueiredo
Sent: Monday, March 19, 2007 12:27 PM
> > The Lua Wiki Math Library Tutorial page[1] says:
> > "But beware! The first random number you get is not really
'randomized'
> > (at least in Windows 2K and OS X)."
> 
> That's the way Pseudorandom number generators usually work. See
> 	http://en.wikipedia.org/wiki/Pseudo-random_number_generator

Hrm, that's not been my experience. To be clear, I understand (and
expect) that feeding it a particular random seed will produce a fixed
sequence. I have never before experienced it where the first result
returned isn't affected by that sequence, however.

I don't see anything on that page that describes the effect under
discussion. Am I missing something, or were you referring to all the
references that page has to deeper concepts, which (presumably) mention
that the first result returned after seeding the random will always be
the same?

For example, here's Ruby running the equivalent code. Note how the
'random' value returned after each seed call is unique, unlike Lua:

C:\>type randomtest_2.rb
the_seed = Time.new.to_i
10.times{ |i|
  the_seed += 1
  puts "Seeding with #{the_seed}"
  srand the_seed
  5.times{
    puts rand( 100 )
  }
}

C:\>ruby -v randomtest_2.rb
ruby 1.8.5 (2006-08-25) [i386-mswin32]
Seeding with 1174329509
66
71
2
18
53
Seeding with 1174329510
68
73
10
52
62
Seeding with 1174329511
36
43
56
15
39
Seeding with 1174329512
26
73
94
94
88
Seeding with 1174329513
28
87
60
17
65
Seeding with 1174329514
28
97
64
75
17
Seeding with 1174329515
49
96
34
20
25
Seeding with 1174329516
31
57
48
83
28
Seeding with 1174329517
45
56
80
47
86
Seeding with 1174329518
80
18
42
1
52