🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.programming
Article #217561

Re: Jak zrobić test za pomocą PractRand?

#217561
From: osobli...
Date: Thu, 23 Sep 2021 00:55
72 lines
7523 bytes
Bardzo szybki powinien też być ulepszony przeze mnie PCG Melissy O'Neil o nazwie XSL-RR-RR (128-bitowy, choć można stworzyć też wersje 64-bitowe i 32-bitowe):

https://en.wikipedia.org/wiki/Permuted_congruential_generator

Normalnie oblewa on dosyć szybko testy PractRand (kod w Pythonie, sam mixer pewnie można napisać lepiej w C, może jako jakieś macro):

import struct
import sys

x = 83866140117348733064738400095399246193
#seed

def PCGmixer(x):
    count1 = x >> 122
    x1 = (x ^ (x >> 64)) & 18446744073709551615
    low64 = (x1 >> count1) | (x1 << (64 - count1)) & 18446744073709551615
    x2 = (x >> 64) & 18446744073709551615
    count2 = low64 & 63
    high64 = (x2 >> count2) | (x2 << (64 - count2)) & 18446744073709551615
    x = (high64 << 64) | low64
    return x

def LCG(x):
    x = (x * 47026247687942121848144207491837523525 + 83866140218348733064834828227924511723) & 340282366920938463463374607431768211455
    return x

while 1 == 1:

    x=LCG(x)
    w=PCGmixer(x)

    split = [(w >> x) & 0xFFFFFFFF for x in reversed(range(0, 128, 32))]
    binary = struct.pack('IIII', split[0], split[1], split[2], split[3])
    sys.stdout.buffer.write(binary)

Ale wystarczy dodać xorowanie kolejnych wyników:

import struct
import sys

x = 83866140117348733064738400095399246193

def PCGmixer(x):
    count1 = x >> 122
    x1 = (x ^ (x >> 64)) & 18446744073709551615
    low64 = (x1 >> count1) | (x1 << (64 - count1)) & 18446744073709551615
    x2 = (x >> 64) & 18446744073709551615
    count2 = low64 & 63
    high64 = (x2 >> count2) | (x2 << (64 - count2)) & 18446744073709551615
    x = (high64 << 64) | low64
    return x

def LCG(x):
    x = (x * 47026247687942121848144207491837523525 + 83866140218348733064834828227924511723) & 340282366920938463463374607431768211455
    return x

w=0

while 1 == 1:

    w_1 = w

    x=LCG(x)
    w=PCGmixer(x)

    w_2 = w_1 ^ w

    #split = [(w_2 >> x) & 0xFFFFFFFF for x in reversed(range(0, 128, 32))]
    #binary = struct.pack('IIII', split[0], split[1], split[2], split[3])
    #sys.stdout.buffer.write(binary)

Żeby zdawał on testy. Oczywiście sam PCGmixer wydłuża czas pracy istotnie (względem bazowego LCG), ale pewnie można go wykonywać szybciej.
Technical Details
Message-ID: <62ec0f80-37a8-42a4-b3e1-b20b1496fe32n@googlegroups.com>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!3.eu.feeder.erje.net!4.us.feeder.erje.net!feeder.erje.net!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
References: <6a2d60cf-5d52-4f70-a0bb-67ac51f2ea47n@googlegroups.com> <0b0e0278-0506-4691-8051-1f73a327e87an@googlegroups.com> <1aabf0e1-8c01-4479-90fc-62d1026d221cn@googlegroups.com> <fcda7316-c8b0-445b-a5d5-2c8db0e2c939n@googlegroups.com> <59524bbe-00b1-4756-b359-19bb000e8641n@googlegroups.com> <2aec1845-1ec1-4e83-835a-ccc9aa089c23n@googlegroups.com> <f201e244-08b1-4ec6-977a-40aba70eac76n@googlegroups.com> <48a87319-4f87-4ace-b9e1-e8c9842514can@googlegroups.com> <5af4b1e3-4d68-4ea8-a5cf-7d2b1075041cn@googlegroups.com> <680b4111-0c0b-4406-ae78-fc27fa1a545an@googlegroups.com> <efe0a67a-6b05-40d2-b877-e5a51f57dd9fn@googlegroups.com> <cb8e26f0-392e-4848-b573-e232e943b6f5n@googlegroups.com> <08cd0111-4022-41af-a03a-a3a4a6307ef6n@googlegroups.com> <c66ce87b-7302-4c87-813b-187c36feffd1n@googlegroups.com> <4a215489-d501-49d5-ade6-cf771ffee901n@googlegroups.com> <7ccd7613-9d6d-4d46-b68f-1db4e9d7a5e3n@googlegroups.com> <9082e2ac-cd7d-436d-80a8-7d12109d3297n@googlegroups.com> <227b1c0e-5d3c-4323-a374-de316aec2ffcn@googlegroups.com> <11f92832-5699-4cf9-be0d-412f9248f4den@googlegroups.com> <97a8c494-64a8-46c0-a17a-114d86aa94d9n@googlegroups.com> <d5976242-a26f-4b4a-93c0-49f7c056c46dn@googlegroups.com> <bf97ae93-0973-4e7d-a7dc-36e681b2479bn@googlegroups.com> <bdc239bf-9878-4a79-a5c4-e007aee2c279n@googlegroups.com> <f453f15f-4c3f-4eee-9714-850a0fb56161n@googlegroups.com> <03af61d9-e808-4daf-82b1-82e45f41372dn@googlegroups.com> <8c2590d8-1517-49f7-b95e-40e5fcaf830bn@googlegroups.com> <f341cef1-76f8-4aa4-ab18-ddf45ba038f3n@googlegroups.com> <a4f24c35-46a4-4dc4-90c0-fa9ee06ce740n@googlegroups.com> <bab05158-796a-4b3f-a52a-42659629ff42n@googlegroups.com> <268d32c4-3f2f-47cd-9544-d15a448f801cn@googlegroups.com> <c9a68c22-8a39-4c63-86e6-cb54d35bfde5n@googlegroups.com> <867ac372-f472-44ea-9346-d99449427a7fn@googlegroups.com> <a1e5bdaf-1701-420b-b2cf-f6831b771a92n@googlegroups.com> <df195a86-c889-47f3-9e9f-e2cb1828efc9n@googlegroups.com> <d2a0fb33-27b9-493e-a88c-fe2e8ec7624bn@googlegroups.com> <21f1661f-f0bc-40af-819b-67e491912f03n@googlegroups.com> <bede20ee-7292-489d-8159-c4460dd09ccdn@googlegroups.com> <1fcfa96a-47ba-4e47-8eea-f9df6a87099bn@googlegroups.com> <715772df-0454-47c9-8dba-ea9f1feb4f77n@googlegroups.com> <18a7e41b-e819-41dc-8749-f4073068d368n@googlegroups.com> <df4a2584-0ce2-4238-9ea2-611b7539a7cdn@googlegroups.com> <9d144f96-4b9c-4b36-b3d3-65f57d60f94cn@googlegroups.com> <585d821d-905b-4480-ae56-23162c4d697fn@googlegroups.com> <412e4c92-95f0-4066-874c-7bcaf7fdc527n@googlegroups.com> <c2aba592-62c0-4c20-b855-3441319f4585n@googlegroups.com> <1b9afe1b-a27d-4769-87af-9731c698bd2an@googlegroups.com> <516761da-c103-438e-89a4-453b5fd105acn@googlegroups.com> <8984b339-4547-45ec-86fd-948cd68fd7f1n@googlegroups.com> <5ef2da7b-8434-4cb9-892c-fbee82a6d058n@googlegroups.com> <aff004e7-7d5a-4bd5-8e4a-3fb8c356f1d4n@googlegroups.com> <6fba279b-cdb5-42b9-9d9e-bc24e7198ecbn@googlegroups.com> <678a6fca-e187-47c4-bdb2-ecbcddac7648n@googlegroups.com> <26012493-7a89-465c-a93e-2ddef0260049n@googlegroups.com> <6943c0be-0407-46e4-b866-379a46765382n@googlegroups.com> <daadfa97-76c3-4ba3-8ee7-801fd5819590n@googlegroups.com> <f6d66139-d2d8-4712-aeb8-074daa0ebf71n@googlegroups.com> <9f2f3109-badc-4840-835f-55ea6da202b6n@googlegroups.com> <6fd36a0c-67a1-4bf6-bd45-12ccfd24e5dfn@googlegroups.com> <8103c74e-4277-4753-889e-6d649adbc60bn@googlegroups.com> <841b915b-c9e1-4c9e-9022-f362a639581cn@googlegroups.com> <e01b8d3a-de81-488a-af25-35eaa18c909cn@googlegroups.com> <d704f6d5-14f3-482c-b7e6-6103499ef8e9n@googlegroups.com> <19d57701-040b-4b15-8661-bd01cc5b5303n@googlegroups.com> <34688ef9-27f1-4963-8b7f-d8d0ed27e145n@googlegroups.com> <ad0c115d-5404-452f-9821-cf90670bd581n@googlegroups.com> <0d16fb14-2a06-43d2-8f38-55a59b2c2752n@googlegroups.com> <890baef9-9d4a-4be8-953f-fa40bc5d2de7n@googlegroups.com> <10e25059-99a6-4934-a312-38657d8651f6n@googlegroups.com> <b009776e-cdd3-48e0-861a-54d002323d1an@googlegroups.com>

Show Full Headers
Complete Article Headers
X-Received: by 2002:a05:6214:1593:: with SMTP id m19mr1837650qvw.36.1632358530820;        Wed, 22 Sep 2021 17:55:30 -0700 (PDT)
X-Received: by 2002:ac8:530c:: with SMTP id t12mr2344163qtn.111.1632358530624; Wed, 22 Sep 2021 17:55:30 -0700 (PDT)
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!3.eu.feeder.erje.net!4.us.feeder.erje.net!feeder.erje.net!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: pl.comp.programming
Date: Wed, 22 Sep 2021 17:55:30 -0700 (PDT)
In-Reply-To: <b009776e-cdd3-48e0-861a-54d002323d1an@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=77.169.12.87; posting-account=5sNFBgoAAAAxlae8lv99mPyGsDs6ynwB
NNTP-Posting-Host: 77.169.12.87
References: <6a2d60cf-5d52-4f70-a0bb-67ac51f2ea47n@googlegroups.com> <0b0e0278-0506-4691-8051-1f73a327e87an@googlegroups.com> <1aabf0e1-8c01-4479-90fc-62d1026d221cn@googlegroups.com> <fcda7316-c8b0-445b-a5d5-2c8db0e2c939n@googlegroups.com> <59524bbe-00b1-4756-b359-19bb000e8641n@googlegroups.com> <2aec1845-1ec1-4e83-835a-ccc9aa089c23n@googlegroups.com> <f201e244-08b1-4ec6-977a-40aba70eac76n@googlegroups.com> <48a87319-4f87-4ace-b9e1-e8c9842514can@googlegroups.com> <5af4b1e3-4d68-4ea8-a5cf-7d2b1075041cn@googlegroups.com> <680b4111-0c0b-4406-ae78-fc27fa1a545an@googlegroups.com> <efe0a67a-6b05-40d2-b877-e5a51f57dd9fn@googlegroups.com> <cb8e26f0-392e-4848-b573-e232e943b6f5n@googlegroups.com> <08cd0111-4022-41af-a03a-a3a4a6307ef6n@googlegroups.com> <c66ce87b-7302-4c87-813b-187c36feffd1n@googlegroups.com> <4a215489-d501-49d5-ade6-cf771ffee901n@googlegroups.com> <7ccd7613-9d6d-4d46-b68f-1db4e9d7a5e3n@googlegroups.com> <9082e2ac-cd7d-436d-80a8-7d12109d3297n@googlegroups.com> <227b1c0e-5d3c-4323-a374-de316aec2ffcn@googlegroups.com> <11f92832-5699-4cf9-be0d-412f9248f4den@googlegroups.com> <97a8c494-64a8-46c0-a17a-114d86aa94d9n@googlegroups.com> <d5976242-a26f-4b4a-93c0-49f7c056c46dn@googlegroups.com> <bf97ae93-0973-4e7d-a7dc-36e681b2479bn@googlegroups.com> <bdc239bf-9878-4a79-a5c4-e007aee2c279n@googlegroups.com> <f453f15f-4c3f-4eee-9714-850a0fb56161n@googlegroups.com> <03af61d9-e808-4daf-82b1-82e45f41372dn@googlegroups.com> <8c2590d8-1517-49f7-b95e-40e5fcaf830bn@googlegroups.com> <f341cef1-76f8-4aa4-ab18-ddf45ba038f3n@googlegroups.com> <a4f24c35-46a4-4dc4-90c0-fa9ee06ce740n@googlegroups.com> <bab05158-796a-4b3f-a52a-42659629ff42n@googlegroups.com> <268d32c4-3f2f-47cd-9544-d15a448f801cn@googlegroups.com> <c9a68c22-8a39-4c63-86e6-cb54d35bfde5n@googlegroups.com> <867ac372-f472-44ea-9346-d99449427a7fn@googlegroups.com> <a1e5bdaf-1701-420b-b2cf-f6831b771a92n@googlegroups.com> <df195a86-c889-47f3-9e9f-e2cb1828efc9n@googlegroups.com> <d2a0fb33-27b9-493e-a88c-fe2e8ec7624bn@googlegroups.com> <21f1661f-f0bc-40af-819b-67e491912f03n@googlegroups.com> <bede20ee-7292-489d-8159-c4460dd09ccdn@googlegroups.com> <1fcfa96a-47ba-4e47-8eea-f9df6a87099bn@googlegroups.com> <715772df-0454-47c9-8dba-ea9f1feb4f77n@googlegroups.com> <18a7e41b-e819-41dc-8749-f4073068d368n@googlegroups.com> <df4a2584-0ce2-4238-9ea2-611b7539a7cdn@googlegroups.com> <9d144f96-4b9c-4b36-b3d3-65f57d60f94cn@googlegroups.com> <585d821d-905b-4480-ae56-23162c4d697fn@googlegroups.com> <412e4c92-95f0-4066-874c-7bcaf7fdc527n@googlegroups.com> <c2aba592-62c0-4c20-b855-3441319f4585n@googlegroups.com> <1b9afe1b-a27d-4769-87af-9731c698bd2an@googlegroups.com> <516761da-c103-438e-89a4-453b5fd105acn@googlegroups.com> <8984b339-4547-45ec-86fd-948cd68fd7f1n@googlegroups.com> <5ef2da7b-8434-4cb9-892c-fbee82a6d058n@googlegroups.com> <aff004e7-7d5a-4bd5-8e4a-3fb8c356f1d4n@googlegroups.com> <6fba279b-cdb5-42b9-9d9e-bc24e7198ecbn@googlegroups.com> <678a6fca-e187-47c4-bdb2-ecbcddac7648n@googlegroups.com> <26012493-7a89-465c-a93e-2ddef0260049n@googlegroups.com> <6943c0be-0407-46e4-b866-379a46765382n@googlegroups.com> <daadfa97-76c3-4ba3-8ee7-801fd5819590n@googlegroups.com> <f6d66139-d2d8-4712-aeb8-074daa0ebf71n@googlegroups.com> <9f2f3109-badc-4840-835f-55ea6da202b6n@googlegroups.com> <6fd36a0c-67a1-4bf6-bd45-12ccfd24e5dfn@googlegroups.com> <8103c74e-4277-4753-889e-6d649adbc60bn@googlegroups.com> <841b915b-c9e1-4c9e-9022-f362a639581cn@googlegroups.com> <e01b8d3a-de81-488a-af25-35eaa18c909cn@googlegroups.com> <d704f6d5-14f3-482c-b7e6-6103499ef8e9n@googlegroups.com> <19d57701-040b-4b15-8661-bd01cc5b5303n@googlegroups.com> <34688ef9-27f1-4963-8b7f-d8d0ed27e145n@googlegroups.com> <ad0c115d-5404-452f-9821-cf90670bd581n@googlegroups.com> <0d16fb14-2a06-43d2-8f38-55a59b2c2752n@googlegroups.com> <890baef9-9d4a-4be8-953f-fa40bc5d2de7n@googlegroups.com> <10e25059-99a6-4934-a312-38657d8651f6n@googlegroups.com> <b009776e-cdd3-48e0-861a-54d002323d1an@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <62ec0f80-37a8-42a4-b3e1-b20b1496fe32n@googlegroups.com>
Subject: Re: Jak zrobić test za pomocą
 PractRand?
From: "osobli...@gmail.com" <osobliwy.nick@gmail.com>
Injection-Date: Thu, 23 Sep 2021 00:55:30 +0000
Lines: 84
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit