Python random sequence with seed

后端 未结 2 1251
别那么骄傲
别那么骄傲 2020-12-09 10:10

I\'m doing this for a school project (so I can\'t use any advanced features) and I\'m using Python 2.6.6.

I have a list of numbers from 1 to 1000 and my seed will be

2条回答
  •  长情又很酷
    2020-12-09 10:50

    A simple check on the python docs http://docs.python.org/library/random.html tells you about

    random.seed([x])
    

    which you can use to initialize the seed.

    To get the items in the order of your initial again, set the seed again and get the random numbers again. You can then use this index to get the content in the list or just use the index for whatever.

    You’d just sort the list and it’d be in sorted order again.

提交回复
热议问题