contexts.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:coordinates 作者: markovmodel 项目源码 文件源码
def random_seed(seed=42):
    """ sets the random seed of Python within the context.

    Example
    -------
    >>> import random
    >>> with random_seed(seed=0):
    ...    random.randint(0, 1000) # doctest: +SKIP
    864
    """
    old_state = random.getstate()
    random.seed(seed)
    try:
        yield
    finally:
        random.setstate(old_state)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号