A random element from the sequence
uses cryptographic-insufficient PG in python, so if you use it in context, where it is not desirable to guess the result of consecutive calls, for example, when generating passwords, then CSpg should be used such as random.syStemrandom () , which uses, which in tu uses the possibilities provided by OS:
#!/usr/bin/env python3 import randomrandom = random.syStemrandom (). Choice (" World A resident "" , "" mafia "" ]) see also :. secrets The module is available with Python 3.6 - its method is just for the systemrandom (). Choice shown above.
every time a different line
so that you could print with each start of the program. Different values from a given sequence, you can create an endless iterator using, which in a circle retus elements from this sequence. To maintain the condition of the iterator between the launches of the program, so that the next value is retued each time, you can use it for serialization:
#!/Usr/bin/bin/bin/bin/bin/bin/bin/bin/bin/bin/bin/ep. python3 idertools Import Pathlib Import pickle # Load items path = Pathlib.path ( 'it.pickle' ) try : data = path.read_bytes () # xxx no File Locking, ignore concurrent Issues except filenotfounderror: # 1st # Create an infinite itrator lieTats values it = itertools.cycle (, }) else : # note: it If you canit trist it.pickle's concentent it it is pickle.loads (Data) # print next item print (#### Save items path.write_bytes (pickle.dumps (it)) # xxx ignore data corruption Issues to avoid (uninhabited) Damage to the file (for example, if the food suddenly disappears during the file recording), you can use a temporary file. See.