eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingJak zrobić test za pomocą PractRand? › Re: Jak zrobić test za pomocą PractRand?
  • X-Received: by 2002:ac8:7194:: with SMTP id w20mr34385765qto.217.1629814824642; Tue,
    24 Aug 2021 07:20:24 -0700 (PDT)
    X-Received: by 2002:ac8:7194:: with SMTP id w20mr34385765qto.217.1629814824642; Tue,
    24 Aug 2021 07:20:24 -0700 (PDT)
    Path: news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!2.eu.feeder.erj
    e.net!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.mixmin.net!p
    roxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp
    .google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
    Newsgroups: pl.comp.programming
    Date: Tue, 24 Aug 2021 07:20:24 -0700 (PDT)
    In-Reply-To: <d...@g...com>
    Injection-Info: google-groups.googlegroups.com; posting-host=77.169.12.87;
    posting-account=5sNFBgoAAAAxlae8lv99mPyGsDs6ynwB
    NNTP-Posting-Host: 77.169.12.87
    References: <6...@g...com>
    <0...@g...com>
    <1...@g...com>
    <f...@g...com>
    <5...@g...com>
    <2...@g...com>
    <f...@g...com>
    <4...@g...com>
    <5...@g...com>
    <6...@g...com>
    <e...@g...com>
    <c...@g...com>
    <0...@g...com>
    <c...@g...com>
    <4...@g...com>
    <7...@g...com>
    <9...@g...com>
    <2...@g...com>
    <1...@g...com>
    <9...@g...com>
    <d...@g...com>
    <b...@g...com>
    <b...@g...com>
    <f...@g...com>
    <0...@g...com>
    <8...@g...com>
    <f...@g...com>
    <a...@g...com>
    <b...@g...com>
    <2...@g...com>
    <c...@g...com>
    <8...@g...com>
    <a...@g...com>
    <d...@g...com>
    <d...@g...com>
    <2...@g...com>
    <b...@g...com>
    <1...@g...com>
    <7...@g...com>
    <1...@g...com>
    <d...@g...com>
    <9...@g...com>
    <5...@g...com>
    <4...@g...com>
    <c...@g...com>
    <1...@g...com>
    <5...@g...com>
    <8...@g...com>
    <5...@g...com>
    <a...@g...com>
    <6...@g...com>
    <6...@g...com>
    <2...@g...com>
    <6...@g...com>
    <d...@g...com>
    User-Agent: G2/1.0
    MIME-Version: 1.0
    Message-ID: <f...@g...com>
    Subject: Re: Jak zrobić test za pomocą PractRand?
    From: "o...@g...com" <o...@g...com>
    Injection-Date: Tue, 24 Aug 2021 14:20:24 +0000
    Content-Type: text/plain; charset="UTF-8"
    Content-Transfer-Encoding: quoted-printable
    Xref: news-archive.icm.edu.pl pl.comp.programming:215577
    [ ukryj nagłówki ]

    wtorek, 24 sierpnia 2021 o 11:46:47 UTC+2 M.M. napisał(a):
    > On Tuesday, August 24, 2021 at 1:43:54 AM UTC+2, o...@g...com wrote:
    > > To też nie działa:
    > >
    > > def to_bytes(num, size):
    > > x = num if num >= 0 else 256**size + num
    > > h = hex(x)[2:].rstrip("L")
    > > return binascii.unhexlify("0"*((2*size)-len(h))+h)
    > >
    > > Wyniki, które otrzymuję są podobne do tego, który podano w przykładzie:
    > >
    > > \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
    \x00\x00\x00'
    > >
    > > Oznacza, to, że prawie na pewno konwertuję dane dobrze. Problem jest nadal z
    przekazaniem tego do PractRand. Nie wiem, czy używam poprawnie:
    > >
    > > sys.stdout.buffer.write(binary)
    > >
    > > Skoro nie działa, ale z tego co widzę może tam być po prostu zmienna w nawiasach,
    więc nie powinno być problemu. Standardowy print zarówno ze znakami nowej linii, jak
    i bez nie działa. Nie sądzę, że tutaj też jest nadal jakiś błąd. Wydaje mi się, że
    dane są wciąż źle podawane.
    > >
    > > Jak podaje dane program:
    > >
    > > #include <cstdio>
    > > #include <cstdint>
    > >
    > > #include <random>
    > >
    > > int main()
    > > {
    > > freopen(NULL, "wb", stdout); // Only necessary on Windows, but harmless.
    > >
    > > std::mt19937 rng(42);
    > >
    > > while (1) {
    > > uint32_t value = rng();
    > > fwrite((void*) &value, sizeof(value), 1, stdout);
    > > }
    > > }
    > >
    > > https://www.pcg-random.org/posts/how-to-test-with-pr
    actrand.html
    > >
    > > I czym to się różni od mojego sposobu?
    > Nie wiem, ale u mnie działa:
    >
    > cat test.py
    > import sys
    > import struct
    >
    > class SimpPRNG:
    > x = 0
    > A = 79908886691
    > B = 8143076871913
    > def __init__( self, seed ):
    > self.x = seed
    > for i in range(1,100):
    > self.g()
    >
    > def g(self):
    > self.x = (self.x * self.A + self.B) & (2**128-1)
    > return self.x >> 123
    >
    > r = SimpPRNG( 1 )
    > buf = 0
    > s = 0
    > while True:
    > t = r.g()
    > for i in range(1,5):
    > buf = buf << 1
    > buf = buf | (t & 1)
    > t = t >> 1
    > s = s + 1
    > if s == 32:
    > sys.stdout.write( struct.pack('I', buf) )
    > s = 0
    > buf = 0
    >
    >
    > python test.py | ../c/PractRand/RNG_test stdin
    > RNG_test using PractRand version 0.94
    > RNG = RNG_stdin, seed = unknown
    > test set = core, folding = standard(unknown format)
    >
    > rng=RNG_stdin, seed=unknown
    > length= 512 kilobytes (2^19 bytes), time= 2.7 seconds
    > no anomalies in 84 test result(s)
    >
    > rng=RNG_stdin, seed=unknown
    > length= 1 megabyte (2^20 bytes), time= 5.8 seconds
    > no anomalies in 94 test result(s)
    >
    > rng=RNG_stdin, seed=unknown
    > length= 2 megabytes (2^21 bytes), time= 11.5 seconds
    > no anomalies in 109 test result(s)
    >
    > rng=RNG_stdin, seed=unknown
    > length= 4 megabytes (2^22 bytes), time= 22.7 seconds
    > no anomalies in 124 test result(s)
    >
    > rng=RNG_stdin, seed=unknown
    > length= 8 megabytes (2^23 bytes), time= 44.5 seconds
    > no anomalies in 135 test result(s)
    >
    > rng=RNG_stdin, seed=unknown
    > length= 16 megabytes (2^24 bytes), time= 87.8 seconds
    > no anomalies in 151 test result(s)
    > ^CTraceback (most recent call last):
    > File "test.py", line 30, in <module>
    > t = t >> 1
    > KeyboardInterrupt
    >
    > Pozdrawim

    U mnie sys.stdout.write(struct.pack('I', buf)) od razu podświetla się jako błąd. Po
    uruchomieniu:

    TypeError: write() argument must be str, not bytes

    Gdy zrobię z argumentu stringa sys.stdout.write(str(struct.pack('I', buf))), to
    oczywiście oblewa. Trzeba tam jeszcze coś prawdopodobnie dodać, żeby to write
    działało w trybie binarnym.

Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj


Następne wpisy z tego wątku

Najnowsze wątki z tej grupy


Najnowsze wątki

Szukaj w grupach

Eksperci egospodarka.pl

1 1 1

Wpisz nazwę miasta, dla którego chcesz znaleźć jednostkę ZUS.

Wzory dokumentów

Bezpłatne wzory dokumentów i formularzy.
Wyszukaj i pobierz za darmo: