FEZ
FEZ

Reputation: 21

random.sample() generating same sequence every time it is run

I run this code on two machines:

from apscheduler.schedulers.asyncio import AsyncIOScheduler

# this part is simplified. It is only here to show how scheduler is basically initialized (for context)
scheduler = AsyncIOScheduler(timezone=utc)
scheduler.start()

# This is real code (with exception of the list)
@scheduler.scheduled_job('interval', minutes=1, misfire_grace_time=None)
async def do_dada_news():
    pages = [...] # shortened for better readability. It is longer than 20 elements
    print("---")
    for page in random.sample(pages, min(len(pages), 20)):
        print(page)

On both machines I get different outputs which are strange:

I expect both machines to have the same behavior. How can this be such a different behavior?

To temporarily fix the problem, I now do random.seed(time.time()*10000) inside do_dada_news(). But that does not feel right.

Upvotes: 2

Views: 48

Answers (0)

Related Questions