Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

/frog/ challenge sqrt(-2): unique (pseudo)random snowflake numbers

Name: Anonymous 2019-01-22 12:49

your're are task: implement a random number generator which works according to the following specification:
  • takes two command-line arguments; first will be the seed, second will be how many numbers to generate
  • outputs numbers separated by newline to stdout
  • if called \(2^{32}\) times, it will output each \(x\) defined as \(0 <= x < 2^{32}\) exactly once
  • order of such outputs will not be trivially predictable, but it doesn't have to be cryptographically secure: \(0, 1, 2, 3 ... 2^{32}\) is not ok but an LSFR is
  • each seed should generate a different sequence, there should not be a single sequence with seeds working as offsets into it

you have one week. the shortest code (in bytes of source code or compiled executable) wins, but submissions will be scored in two separate categories: those that achieve uniqueness algorithmically and those that guarantee it by explicitly caching the results. the category which does not use caching should be seen as the more prestigious one since caching is a trivial hack and it will ruin performance and/or memory usage for large sequences

Name: Anonymous 2019-01-22 13:35

Trivial 64bit RNG in 99 bytes
http://void.wikidot.com/code:99byterng-c

Name: Anonymous 2019-01-22 13:55

>>2
does not meet the spec:
  • no uniqueness guarantee
  • no argv[] parsing
  • no other way to specify a seed
  • no other way to specify how many numbers to output
  • most importantly, no guarantee that all 32-bit numbers will be printed exactly once

Name: Anonymous 2019-01-22 15:38

>>3
meet this
*grabs dick*

Name: Anonymous 2019-01-22 17:07

disregard, I suck cocks Edited on 22/01/2019 17:24.

Name: Anonymous 2019-01-22 17:17

so just to be clear, you're essentially asking for a program that computes a permutation (bc uniqueness) of the 32-bit integers. Since each seed should generate a different permutation, you'd need a function F : nat -> nat -> nat, such that (F n) is a non-trivial permutation for each n. (and then just call it in sequence to print the first k numbers)

There are only finitely many permutations, so it's impossible to generate a different one for __every__ seed. There should be a requirement that we can assume the seed to have log(2^32-factorial) many bits, so there are at most 2^32-factorial different seeds.

Name: Anonymous 2019-01-22 17:24

python 3, no caching. try figuring out how it works, you anuses
import struct
import random
import sys
i='I';s=struct;l=sys.argv;m=range;a=[x for x in m(256)];exec('random.s%s'*2%('eed(l[1]);','huffle(a)'))
def g(x,y,z):
c=0xFF&(z>>8);d=0xFF&z;e=a[d^x[(4*y+0)%10]]^c;f=a[e^x[(4*y+1)%10]]^d;h=a[f^x[(4*y+2)%10]]^e; i=a[h^x[(4*y+3)%10]]^f;return((h<<8)+i)
def j(k,b):
c=0;d=(b[0]<<8)+b[1];e=(b[2]<<8)+b[3]
for _ in k:
e^=g(k,c,d)^c;c+=1;d^=g(k,c,e)^c;c+=1
return bytes((e>>8,d&0xFF,e>>8,d&0xFF))
for x in m(int(l[2])):
print(s.unpack(i,j(b'0'*12,s.pack(i,x)))[0])

Name: Anonymous 2019-01-22 17:26

>>6
There are only finitely many permutations, so it's impossible to generate a different one for __every__ seed. There should be a requirement that we can assume the seed to have log(2^32-factorial) many bits, so there are at most 2^32-factorial different seeds.
OP here, your're are right, of course. sorry if I wasn't being clear

Name: Anonymous 2019-01-22 17:43

>>6,8
to be absolutely precise: you don't need to be able to generate exactly \(2^{32}!\) permutations, although doing that would certainly be impressive. if you have a 32-bit seed and each of them gets a unique permutation, that's ok. the solution in >>7 looks like it has \(255!\) solutions, which is even better. I just want to prevent anuses gaming the system by e.g. creating a single cyclic group and having the 'seed' be generator's starting point.

tl;dr if your're are seed acts like an actual seed, I'll accept it

Name: Anonymous 2019-01-22 22:54

warning, slow! also seed 0 means no randomness
import System.Environment;import Data.List;
a=(permutations[1..2^32]!!).(`mod`2^32).(*(2^31-1))
b x=take(y!!1)(a(y!!0))
where y=map(read::String->Int)x
main=getArgs>>=(print.unlines.(map show).b)

Name: Anonymous 2019-01-23 7:03

>>10
this code manages to be as slow as the caching solution without actually caching!

Name: Anonymous 2019-01-23 7:22

import std.stdio, std.bigint, std.algorithm, std.range;

auto cumu(in uint n) {
__gshared cache = [[1.BigInt]];
foreach (l; cache.length .. n + 1) {
auto r = [0.BigInt];
foreach (x; 1 .. l + 1)
r ~= r.back + cache[l - x][min(x, l - x)];
cache ~= r;
}
return cache[n];
}

auto row(in uint n) {
auto r = n.cumu;
return n.iota.map!(i => r[i] - r[i]);
}

void main() {
foreach (x; 1 .. 11)
writefln("%2d: %s", x, x.row);

foreach (x; [23, 123, 1234])
writeln(x, " ", x.cumu.back);
}

Name: Anonymous 2019-01-23 8:03

>>12
this is the ouptut I got:
1: [0]
2: [0, 0]
3: [0, 0, 0]
4: [0, 0, 0, 0]
5: [0, 0, 0, 0, 0]
6: [0, 0, 0, 0, 0, 0]
7: [0, 0, 0, 0, 0, 0, 0]
8: [0, 0, 0, 0, 0, 0, 0, 0]
9: [0, 0, 0, 0, 0, 0, 0, 0, 0]
10: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
23 1255
123 2552338241
1234 156978797223733228787865722354959930


not sure what it's supposed to be but it's not doing what >>1 said

Name: Anonymous 2019-01-23 11:27

import sys,random
random.seed(sys.argv[1]);a=random.randint(0,2**32);i=0
exec("i+=1;print(i*a*(2**31-1)%2**32);"*int(sys.argv[2]))

Name: Anonymous 2019-01-23 11:50

>>14
slightly improved:
import sys,random;r=random;_,b,c=sys.argv;r.seed(b);a=r.randint(0,2**32);i=0;exec("i+=1;print(i*a*(2**31-1)%2**32);"*int(c)))

Name: Anonymous 2019-01-28 12:49

bamp pant

Name: Anonymous 2019-01-28 12:55

Using the pumble nut lang:
Brap braaaaaaap brrrrap bbrrrraaaaaap braaaap bbbbraaap bbbbbrrrrappp brapppp brap PUMBLENUTS

Name: Anonymous 2019-01-28 13:17

>>17
LLLLLLLLLLLLEEEEEEEEEEEEEEEEELLLLLLLLLL XDDDDDDDDDDDDDDDDDDDDD
E/G/IN MEME, /G/RO!

Name: Anonymous 2019-01-28 13:53

>>18
I am autistic.

Name: Anonymous 2019-01-28 14:01

>>19
Don't worry I chuckled.

Name: Anonymous 2019-01-28 14:48

I had a big and liquid one.

Name: Anonymous 2019-01-29 3:39

I had dubs.

Name: Anonymous 2019-01-29 18:00

concluding the challenge:

the winner in the non-cached category is: >>15
the winner in the cached category is: fucking nobody because the only submitted entry (>>13) didn't meet the spec
special award for strongest randomness and uniqueness guarantees goes to: >>7 (as this solution basically amounts to a block cipher in CTR mode)

Name: >>13 2019-01-29 18:14

>>23
Sorry I just posted random D source code. I am autistic.

Name: Anonymous 2019-01-29 18:19

>>24
we all are

Name: Anonymous 2019-01-31 18:10

>>25
Mama said that I am not autistic. Stop lying.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List