why this happend using model random?
Fredrik Lundh
fredrik at pythonware.com
Tue May 10 06:16:15 EDT 2005
"flyaflya" wrote:
> from random import *
>
> col = [0 for i in range(10)]
> a = [col for i in range(10)]
http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list
> seed()
> for i in range(10):
> for j in range(10):
> a[i][j] = randint(0, 100)
> print a
>
> the result is:
> [[78, 65, 35, 5, 68, 60, 1, 51, 81, 70],
> [78, 65, 35, 5, 68, 60, 1, 51, 81, 70],
> [78, 65, 35, 5, 68, 60, 1, 51, 81, 70], .....]
> why result isn't true random?
because you've assigned all the values to the same list ("col"). see the link above
for details.
</F>
More information about the Python-list
mailing list