# [Tutor] seed & random !?

Andrei Kulakov ak@silmarill.org
Sun, 14 Oct 2001 05:38:14 -0400

```On Sun, Oct 14, 2001 at 02:27:21AM -0700, necati kaya wrote:
> Hi,
> I am trying to generate different new_list randomly in
> each step of the loop from original_list, but I can
> not. As the example;
> original_list=['1','2','3','4'] and my program produce
> those new_lists randomly, but
>
> ['4', '2', '3', '1']   ==>
> ['1', '4', '2', '3']         Both are same
> ['4', '2', '3', '1']   ==>
> ['3', '2', '1', '4']
> ['2', '4', '3', '1']
>
> I tried to use seed function, but it gave me all the
> same results. Do you have any suggestion to have
> different new_list which is generated from
> original_list in every step.

If I understood right, you want to create random lists that have the same
elements as a given list, but not in the same order.. if that's true, you
can do this with my_list.shuffle:

>>> from random import shuffle
>>> l
[3, 4, 2, 1]
>>> from copy import copy
>>> l2 = copy(l)
>>> shuffle(l2)
>>> l2
[2, 4, 3, 1]
>>> l
[3, 4, 2, 1]
>>> for i in range(10):
...  shuffle(l2)
...  if l != l2:
...   print l2
...
[3, 1, 4, 2]
[1, 2, 4, 3]
[4, 3, 2, 1]
[2, 1, 4, 3]
[1, 3, 4, 2]
[4, 3, 2, 1]
[2, 1, 4, 3]
[3, 4, 1, 2]
[4, 1, 2, 3]
[2, 1, 4, 3]
>>> l
[3, 4, 2, 1]

Instead of printing, you can append it to a list of random lists..

Hope that's what you wanted :P

> Regards,
> umit
>
> Here is my code:
>
>
> from random import Random
> import random
>
> original_list=['1','2','3','4']
> for j in range(0, 5):
>     temp_list = original_list[:]
>     new_list=[]
>     for i in range(0, len(original_list)):
> #            random.seed()
> #??????????????
>             choosen_item = random.choice(temp_list)
>             new_list.append(choosen_item)
>             temp_list.remove(choosen_item)
>     print new_list
>     print
>
>
> __________________________________________________
> Do You Yahoo!?
> Make a great connection at Yahoo! Personals.
> http://personals.yahoo.com
>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

--
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org

```