Live data from Hacker News

Show HN: Prime Number Grid Visualizer

enda.sh

41–50 of 53 posts

Re: Show HN: Prime Number Grid Visualizer

#41

Reminds me of a really cool coding trick to get a "random" permutation of an array in O(1) time/memory. https://lemire.me/blog/2017/09/18/visiting-all-values-in-an-...

That's neither random nor O(1). I think everybody reading the link immediately understands what you mean, but I whished this community would use its technical terminology more carefully.

Re: Show HN: Prime Number Grid Visualizer

#43

Reminds me of a really cool coding trick to get a "random" permutation of an array in O(1) time/memory. https://lemire.me/blog/2017/09/18/visiting-all-values-in-an-...

That's neither random nor O(1). I think everybody reading the link immediately understands what you mean, but I whished this community would use its technical terminology more carefully.

I use "random" in quotation marks because it communicates the topic effectively and is very straight to the point. Colloquially, when people say "random" in the context of algorithms, it's generally understood to mean "pseudorandom" or "quasirandom". The trick is essentially an LCG using coprime numbers.

The blog post uses "random" in quotations as well in its title.

I call it O(1) because the ordering is fully determined just by choosing an arbitrary prime number. It's constant time to "reorder" the elements and also constant time to get the i'th element in the permutation. This is in contrast to something like the the Fisher-Yates shuffle which permutes the elements in O(n) time.

Re: Show HN: Prime Number Grid Visualizer

#44

Reminds me of a really cool coding trick to get a "random" permutation of an array in O(1) time/memory. https://lemire.me/blog/2017/09/18/visiting-all-values-in-an-...

Feistel networks are another way to map your index from linear sequence to a pseudorandom permutation.

Re: Show HN: Prime Number Grid Visualizer

#45
post #14

Ha, super, thanks for making it. Check out 431 columns - this yields no obvious persistent patterns.

I think you'll find this to be the case with any prime.

Not really. There are almost always clearly visible diagonals. Try 199, 211, 223, etc.

Re: Show HN: Prime Number Grid Visualizer

#46
post #42

The trick is to do 88 columns, punch them out on a roll, and run it through a player piano.

this deserves more upvotes

If someones implements it in a webpage, I expect it to be a nice post for HN.

It will sound horrible. IIRC if you know music and choose only 4 notes correctly, even random notes may not sound too bad. So perhaps the version with 88/12*4 columns may be better.

Re: Show HN: Prime Number Grid Visualizer

#49
post #44

Reminds me of a really cool coding trick to get a "random" permutation of an array in O(1) time/memory. https://lemire.me/blog/2017/09/18/visiting-all-values-in-an-...

Feistel networks are another way to map your index from linear sequence to a pseudorandom permutation.

I was reading into it and came across your blog post. It's a good followup read.

It has better avalanching compared to indexing by `(i * prime) % n`, but at the tradeoff of `n` being restricted to powers of 2.

Post reply on HN