Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung


Quelle  test_random.py   Sprache: Python

 

from __future__ import annotations
import random

import pytest

from sympy.core.random import random as rand, seed, shuffle, _assumptions_shuffle
from sympy.core.symbol import Symbol, symbols
from sympy.functions.elementary.trigonometric import sin, acos
from sympy.abc import x


@pytest.mark.thread_unsafe(reason="resets and consumes process-global RNG state")
def test_random():
    random.seed(42)
    a = random.random()
    random.seed(42)
    Symbol('z').is_finite
    b = random.random()
    assert a == b

    got = set()
    for i in range(2):
        random.seed(28)
        m0, m1 = symbols('m_0 m_1', real=True)
        _ = acos(-m0/m1)
        got.add(random.uniform(0,1))
    assert len(got) == 1

    random.seed(10)
    y = 0
    for i in range(4):
        y += sin(random.uniform(-10,10) * x)
    random.seed(10)
    z = 0
    for i in range(4):
        z += sin(random.uniform(-10,10) * x)
    assert y == z


@pytest.mark.thread_unsafe(reason="resets and consumes process-global RNG state")
def test_seed():
    assert rand() < 1
    seed(1)
    a = rand()
    b = rand()
    seed(1)
    c = rand()
    d = rand()
    assert a == c
    if not c == d:
        assert a != b
    else:
        assert a == b

    abc = 'abc'
    first = list(abc)
    second = list(abc)
    third = list(abc)

    seed(123)
    shuffle(first)

    seed(123)
    shuffle(second)
    _assumptions_shuffle(third)

    assert first == second == third

Messung
CHZG
849810094

¤ Dauer der Verarbeitung: 0.3 Sekunden  (vorverarbeitet am  2026-11-24) ¤

*© Formatika GbR, Deutschland







                                                                                                                                                                                                                                                                                                                                                                                                     

 

Neuigkeiten

Aktuelles
Motto des Tages

Open Source Software


Gedichte
Musik
Bilder

Jenseits des Üblichen

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1,188,305
#Domains=919,449