eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingProsty generator pseudolosowy 8bit z limitem
Ilość wypowiedzi w tym wątku: 51

  • 51. Data: 2017-12-09 16:27:39
    Temat: Re: Prosty generator pseudolosowy 8bit z limitem
    Od: "M.M." <m...@g...com>

    On Friday, December 8, 2017 at 5:53:22 PM UTC+1, M.M. wrote:
    > 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;
    > }

    Całego diehardera przeszedł na m=30. Nie wiadomo czy dla innych zarodków też
    przejdzie, ale jak generator nie musi być super równomierny, a ma być
    bardzo szybki, to chyba nie ma nic lepszego.


    Generator zwraca tylko 8 najmłodszych bitów. Ciekawe czy działałby lepiej,
    gdyby zwracał 8 innych bitów niż najstarsze, bo na wydajność to praktycznie
    by nie wpłynęło. Generator może też zwracać więcej bitów, np. 16 bitów, lub 32 bity,
    a jakby go zaimplementować na typie uint64 lub uint128, to mógłby
    zwracać 64 lub 128 bitów. Przyspieszyłoby go to jeszcze do 16 razy. Jak
    myślicie, jakość generowanych liczb by spadła?


    Wyniki testu dla 8 najmłodszych bitów:

    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
    marsaglia_tsang_gcd| 0| 10000000| 3000|0.83716130| PASSED
    marsaglia_tsang_gcd| 0| 10000000| 3000|0.05530917| PASSED
    sts_monobit| 1| 100000| 3000|0.85138074| PASSED
    sts_runs| 2| 100000| 3000|0.44074715| PASSED
    sts_serial| 1| 100000| 3000|0.21861505| PASSED



    sts_serial| 2| 100000| 3000|0.28454007| PASSED



    sts_serial| 3| 100000| 3000|0.61438900| PASSED



    sts_serial| 3| 100000| 3000|0.22112971| PASSED



    sts_serial| 4| 100000| 3000|0.95517930| PASSED



    sts_serial| 4| 100000| 3000|0.16562539| PASSED



    sts_serial| 5| 100000| 3000|0.28466376| PASSED



    sts_serial| 5| 100000| 3000|0.10776582| PASSED



    sts_serial| 6| 100000| 3000|0.45920174| PASSED



    sts_serial| 6| 100000| 3000|0.20303651| PASSED



    sts_serial| 7| 100000| 3000|0.49722161| PASSED



    sts_serial| 7| 100000| 3000|0.80685114| PASSED



    sts_serial| 8| 100000| 3000|0.41749281| PASSED
    sts_serial| 8| 100000| 3000|0.94116829| PASSED
    sts_serial| 9| 100000| 3000|0.53222747| PASSED
    sts_serial| 9| 100000| 3000|0.58938752| PASSED
    sts_serial| 10| 100000| 3000|0.26245753| PASSED
    sts_serial| 10| 100000| 3000|0.44889624| PASSED
    sts_serial| 11| 100000| 3000|0.02441041| PASSED
    sts_serial| 11| 100000| 3000|0.00181544| WEAK
    sts_serial| 12| 100000| 3000|0.04469190| PASSED
    sts_serial| 12| 100000| 3000|0.15885960| PASSED
    sts_serial| 13| 100000| 3000|0.02979468| PASSED
    sts_serial| 13| 100000| 3000|0.77864508| PASSED
    sts_serial| 14| 100000| 3000|0.00025286| WEAK
    sts_serial| 14| 100000| 3000|0.03756306| PASSED
    sts_serial| 15| 100000| 3000|0.01495578| PASSED
    sts_serial| 15| 100000| 3000|0.25646264| PASSED
    sts_serial| 16| 100000| 3000|0.10219212| PASSED
    sts_serial| 16| 100000| 3000|0.49916583| PASSED
    rgb_bitdist| 1| 100000| 3000|0.24353012| PASSED
    rgb_bitdist| 2| 100000| 3000|0.33193645| PASSED
    rgb_bitdist| 3| 100000| 3000|0.77606973| PASSED
    rgb_bitdist| 4| 100000| 3000|0.48072339| PASSED
    rgb_bitdist| 5| 100000| 3000|0.02841032| PASSED
    rgb_bitdist| 6| 100000| 3000|0.72828838| PASSED
    rgb_bitdist| 7| 100000| 3000|0.06921169| PASSED
    rgb_bitdist| 8| 100000| 3000|0.41825331| PASSED
    rgb_bitdist| 9| 100000| 3000|0.91108880| PASSED
    rgb_bitdist| 10| 100000| 3000|0.43222942| PASSED
    rgb_bitdist| 11| 100000| 3000|0.61747840| PASSED
    rgb_bitdist| 12| 100000| 3000|0.30358537| PASSED
    rgb_minimum_distance| 2| 10000| 30000|0.04817726| PASSED



    rgb_minimum_distance| 3| 10000| 30000|0.83114815| PASSED



    rgb_minimum_distance| 4| 10000| 30000|0.00560345| PASSED



    rgb_minimum_distance| 5| 10000| 30000|0.00668000| PASSED



    rgb_permutations| 2| 100000| 3000|0.24834843| PASSED



    rgb_permutations| 3| 100000| 3000|0.07901995| PASSED



    rgb_permutations| 4| 100000| 3000|0.86363673| PASSED



    rgb_permutations| 5| 100000| 3000|0.53472342| PASSED



    rgb_lagged_sum| 0| 1000000| 3000|0.88718714| PASSED



    rgb_lagged_sum| 1| 1000000| 3000|0.26184722| PASSED



    rgb_lagged_sum| 2| 1000000| 3000|0.96379709| PASSED



    rgb_lagged_sum| 3| 1000000| 3000|0.42731884| PASSED



    rgb_lagged_sum| 4| 1000000| 3000|0.97153879| PASSED
    rgb_lagged_sum| 5| 1000000| 3000|0.44772137| PASSED
    rgb_lagged_sum| 6| 1000000| 3000|0.98129048| PASSED
    rgb_lagged_sum| 7| 1000000| 3000|0.14721559| PASSED
    rgb_lagged_sum| 8| 1000000| 3000|0.56080283| PASSED
    rgb_lagged_sum| 9| 1000000| 3000|0.10075053| PASSED
    rgb_lagged_sum| 10| 1000000| 3000|0.52807343| PASSED
    rgb_lagged_sum| 11| 1000000| 3000|0.16251504| PASSED
    rgb_lagged_sum| 12| 1000000| 3000|0.06012319| PASSED
    rgb_lagged_sum| 13| 1000000| 3000|0.02819854| PASSED



    rgb_lagged_sum| 14| 1000000| 3000|0.56292316| PASSED



    rgb_lagged_sum| 15| 1000000| 3000|0.03627918| PASSED



    rgb_lagged_sum| 16| 1000000| 3000|0.31141215| PASSED



    rgb_lagged_sum| 17| 1000000| 3000|0.23430245| PASSED



    rgb_lagged_sum| 18| 1000000| 3000|0.96322096| PASSED



    rgb_lagged_sum| 19| 1000000| 3000|0.05275294| PASSED



    rgb_lagged_sum| 20| 1000000| 3000|0.16858733| PASSED



    rgb_lagged_sum| 21| 1000000| 3000|0.27858252| PASSED



    rgb_lagged_sum| 22| 1000000| 3000|0.86056685| PASSED



    rgb_lagged_sum| 23| 1000000| 3000|0.49540101| PASSED



    rgb_lagged_sum| 24| 1000000| 3000|0.96278283| PASSED



    rgb_lagged_sum| 25| 1000000| 3000|0.85687248| PASSED
    rgb_lagged_sum| 26| 1000000| 3000|0.52521927| PASSED
    rgb_lagged_sum| 27| 1000000| 3000|0.47528244| PASSED
    rgb_lagged_sum| 28| 1000000| 3000|0.68680905| PASSED
    rgb_lagged_sum| 29| 1000000| 3000|0.95196801| PASSED
    rgb_lagged_sum| 30| 1000000| 3000|0.35409145| PASSED
    rgb_lagged_sum| 31| 1000000| 3000|0.79745235| PASSED
    rgb_lagged_sum| 32| 1000000| 3000|0.93842994| PASSED
    rgb_kstest_test| 0| 10000| 30000|0.00167822| WEAK
    dab_bytedistrib| 0| 51200000| 30|0.80854497| PASSED
    dab_dct| 256| 50000| 30|0.86426890| PASSED
    Preparing to run test 207. ntuple = 0
    dab_filltree| 32| 15000000| 30|0.66975905| PASSED
    dab_filltree| 32| 15000000| 30|0.56236231| PASSED
    Preparing to run test 208. ntuple = 0
    dab_filltree2| 0| 5000000| 30|0.59454036| PASSED
    dab_filltree2| 1| 5000000| 30|0.75484914| PASSED
    Preparing to run test 209. ntuple = 0
    dab_monobit2| 12| 65000000| 30|0.23905375| PASSED

    real 1437m24.217s
    user 1948m33.944s
    sys 88m11.892s

strony : 1 ... 5 . [ 6 ]


Szukaj w grupach

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: