eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingProsty generator pseudolosowy 8bit z limitemRe: Prosty generator pseudolosowy 8bit z limitem
  • X-Received: by 10.31.165.2 with SMTP id o2mr108200vke.2.1512752000380; Fri, 08 Dec
    2017 08:53:20 -0800 (PST)
    X-Received: by 10.31.165.2 with SMTP id o2mr108200vke.2.1512752000380; Fri, 08 Dec
    2017 08:53:20 -0800 (PST)
    Path: news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit
    0.net!peer03.am4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-medi
    a.com!news.highwinds-media.com!g35no1237181qtk.1!news-out.google.com!v55ni1749q
    tc.0!nntp.google.com!g35no1237180qtk.1!postnews.google.com!glegroupsg2000goo.go
    oglegroups.com!not-for-mail
    Newsgroups: pl.comp.programming
    Date: Fri, 8 Dec 2017 08:53:20 -0800 (PST)
    In-Reply-To: <p0a0td$1lis$1@gioia.aioe.org>
    Complaints-To: g...@g...com
    Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=77.254.45.52;
    posting-account=xjvq9QoAAAATMPC2X3btlHd_LkaJo_rj
    NNTP-Posting-Host: 77.254.45.52
    References: <a...@g...com>
    <a...@g...com>
    <ovkuhb$abp$1@gioia.aioe.org>
    <2...@g...com>
    <a...@n...v.pl>
    <7...@g...com>
    <a...@n...v.pl>
    <2...@g...com>
    <f...@g...com>
    <8...@g...com>
    <p09f6j$ot4$1@gioia.aioe.org> <a...@n...v.pl>
    <p0a0td$1lis$1@gioia.aioe.org>
    User-Agent: G2/1.0
    MIME-Version: 1.0
    Message-ID: <2...@g...com>
    Subject: Re: Prosty generator pseudolosowy 8bit z limitem
    From: "M.M." <m...@g...com>
    Injection-Date: Fri, 08 Dec 2017 16:53:20 +0000
    Content-Type: text/plain; charset="UTF-8"
    Content-Transfer-Encoding: quoted-printable
    X-Received-Bytes: 6176
    X-Received-Body-CRC: 992102474
    Xref: news-archive.icm.edu.pl pl.comp.programming:211864
    [ ukryj nagłówki ]

    On Thursday, December 7, 2017 at 1:10:25 AM UTC+1, AK wrote:
    > Użytkownik "slawek" <f...@f...com> napisał:
    > >> rand() & 0xFF // ;)
    > >
    > > Lepiej (rand() >> 4) & 0xff
    > >
    > > Najniższe bity wywalić.
    >
    > To prawda, ale oni chcieli "szybciej", a nie "lepiej" :)
    > PS: Oczywiscie generalnie to byl zart (no nie tak znow w 100%:)
    >
    > AK

    Generator Fibonacciego też można napisać w 10 minut na
    kolanie i, jak na razie, przeszedł kilkanaście początkowych
    diehardera nawet na m=30. Generowanie liczb jest ekstremalnie
    szybkie, nie zawiera nawet ifa. Niestety nie wiadomo czy dla
    innych zarodków też zachowa się tak samo dobrze :/ I drugie
    niestety: poniższa implementacja wymaga ponad 16k bajtów ram.

    Kod:
    class FibRnd {
    private:
    unsigned int a,b,c;
    unsigned int *x;
    unsigned int max;

    public:
    FibRnd(unsigned int seed) {
    max = 1<<12;
    a = 0;
    b = 16;
    c = max-1;
    x = new unsigned int[max];
    for( unsigned int i=0 ; i<max * 4 ; i++ ) {
    x[i%max] <<= 4;
    x[i%max] ^= seed = ((seed * 359ull + 3733ull) % 1057767ull);
    }
    }
    ~FibRnd() {
    delete[] x;
    }
    unsigned int operator ()() {
    a = (a+1)&(max-1);
    b = (b+1)&(max-1);
    c = (c+1)&(max-1);
    return x[c] = x[a] + x[b];
    }

    };

    int main( int argc, char *argv[] ) {
    FibRnd rnd((unsigned int)time(NULL));
    while( true ) {
    unsigned char x[N];
    for( int i=0 ; i<N ; i++ )
    x[i] = (unsigned char)rnd();
    fwrite( x , 1 , N , stdout );
    }
    return 0;
    }

    Test:
    time ./frnd | dieharder -a -m 30 -g 200
    #===================================================
    ==========================#
    # dieharder version 3.31.1 Copyright 2003 Robert G. Brown #
    #===================================================
    ==========================#
    rng_name |rands/second| Seed |
    stdin_input_raw| 3.00e+07 |2482448351|
    #===================================================
    ==========================#
    test_name |ntup| tsamples |psamples| p-value |Assessment
    #===================================================
    ==========================#
    diehard_birthdays| 0| 100| 3000|0.29234458| PASSED
    diehard_operm5| 0| 1000000| 3000|0.51398474| PASSED
    diehard_rank_32x32| 0| 40000| 3000|0.36767415| PASSED
    diehard_rank_6x8| 0| 100000| 3000|0.69227346| PASSED
    diehard_bitstream| 0| 2097152| 3000|0.30960016| PASSED
    diehard_opso| 0| 2097152| 3000|0.85888419| PASSED
    diehard_oqso| 0| 2097152| 3000|0.67207083| PASSED
    diehard_dna| 0| 2097152| 3000|0.00012554| WEAK
    diehard_count_1s_str| 0| 256000| 3000|0.51597335| PASSED
    diehard_count_1s_byt| 0| 256000| 3000|0.26197695| PASSED
    diehard_parking_lot| 0| 12000| 3000|0.17469806| PASSED
    diehard_2dsphere| 2| 8000| 3000|0.54418532| PASSED
    diehard_3dsphere| 3| 4000| 3000|0.87789531| PASSED
    diehard_squeeze| 0| 100000| 3000|0.26815462| PASSED
    diehard_sums| 0| 100| 3000|0.00000000| FAILED
    diehard_runs| 0| 100000| 3000|0.01445376| PASSED
    diehard_runs| 0| 100000| 3000|0.00537657| PASSED
    diehard_craps| 0| 200000| 3000|0.93729302| PASSED
    diehard_craps| 0| 200000| 3000|0.34274658| PASSED



    Pozdrawiam

    P.S.
    Nie patrzcie na diehard_sums, bo ten test zawiera błędy.


Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj


Następne wpisy z tego wątku

  • 09.12.17 16:27 M.M.

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: