LABSS/NetLogo2Mesa

delete time from model.py, update in tutorial

Closed this issue · 4 comments

Module time is not used in model.py. Could it have been used in the previous editions to generate seed and now substituted with os.urandom in the VirusModel class?

In that case, in #### Scheduler in the Tutorial

   class VirusModel(Model):

    def __init__(self, number_of_nodes=150, seed=int(time.time() % 60)):

should be substituted with:

class VirusModel(Model):

 def __init__(self, number_of_nodes=150, seed=int.from_bytes(os.urandom(4), sys.byteorder))```

for coherence with the code

I'd keep time.time(), it's not a tutorial on cryptography...

In Python, when you need to initialize the random number generator with a seed, both time.time() and os.urandom() can be used, but they serve different purposes, and the choice depends on your specific requirements:

  1. Using time.time():

    • time.time() returns the current time in seconds since the epoch (typically January 1, 1970).
    • It's useful when you want to create a seed that changes each time your program runs, creating a different sequence of random numbers on each run.
    import random
    import time
    
    seed = int(time.time())
    random.seed(seed)

    This is suitable for scenarios where you want randomness for each run of your program or where the random sequence should be related to the current time.

  2. Using os.urandom():

    • os.urandom() generates random bytes from the operating system's cryptographic random number generator.
    • It's suitable for cases where you need a high degree of randomness and unpredictability, such as cryptographic applications or secure random number generation.
    import random
    import os
    
    seed = int.from_bytes(os.urandom(4), byteorder="big")
    random.seed(seed)

    This approach is more secure and suitable for applications that require strong randomness guarantees.

In summary, the choice between time.time() and os.urandom() depends on your specific use case. If you need a simple, time-based seed for non-cryptographic purposes, time.time() is sufficient. However, if you require a high degree of randomness and security, os.urandom() is the better choice.

OK, in the tutorial the line with seed=int(time.time() % 60) remains as leftover of previous editions. I would keep with os.urandom(8) for coherence with rest of tutorial and code. And in code os.urandom(8) because it allows replication of outcome shown as agreed.

Agreed as from disucssion.