Live data from Hacker News

Algorithm No One Knows About (2016)

getkerf.wordpress.com

131–140 of 200 posts

Re: Algorithm No One Knows About (2016)

#131
post #47

A bunch of comments here are missing the main point: Unless you have an Exabyte of memory, you can't use any kind of data structure to remember which cards you've already picked among 2^64 of them. The goal here is an algorithm that generates the selected cards, one by one, in order, as if from a coroutine that only uses a tiny, constant amount of memory. So, no arrays, lists, sets, hash tables, bitmaps, etc., even i…

If you can store 2^64 data points, why cant you store 2^63 indexes? That's a very small increase in memory requirements.

It might be easy to generate and output the 2^64 data points, because you can throw them away. With 2^63 indices you need to keep them around.

Re: Algorithm No One Knows About (2016)

#133
post #112

Earlier quoted context omitted.

This works, but only if you're sampling the exact same space as the block size. For example, if your cipher outputs 64-bit blocks, but you want to sample in 2^32, you're back to the drawing board, because there's no way to truncate the cipher output without risking duplicates.

You can use the "hasty pudding trick" to truncate the cipher output without risking duplicates. It is inefficient if the block space of the cipher is much larger than the sampling space, though. However, you can also use a Feistel network to create a block cipher for an arbitrary bit length. So, you can always bound the block space to be no more than twice the sampling space, which is okay.

What's the hasty pudding trick? Is it related to the Hasty Pudding cipher?

Re: Algorithm No One Knows About (2016)

#134

The last time I wanted an unpredictable, non-repeating sampling of 64-bit numbers, I used a symmetric cipher in CTR mode. Essentially, start with a random key and a random value, return the encrypted version of it, then the encrypted version of its increment, and so on. Returns every number in the range, with no predictability.

In a similar vein, I use a PRNG (based on Blake2b cryptographic hash) and mask off bits for the required domain.

Re: Algorithm No One Knows About (2016)

#135

”Here’s a program roughly 0% of programmers know how to write: generate a list of random tweets, without duplication. […] Stated more formally: given non-negative integers k and n with k , generate a list of k distinct random numbers, each less than n .“ I think that knowing k beforehand makes it a different, easier problem. I don’t see how, if you don’t know k beforehand, you can do without enough memory to store a…

I don't see why you'd need to generate a permutation?

Re: Algorithm No One Knows About (2016)

#137
post #63
post #54

Earlier quoted context omitted.

That seems correct. On top of that, if you ever need to choose more than half, you choose n-k first then reverse the set. Could it be that the distribution condition is not satisfied? Although I don’t see how. The article could’ve explained the problem better (I mean it keeps reffering to “draw without replacement” - what does that even mean).

The "choose n-k" trick is quite nice. It has one big downside though, which is that you can't start reporting any results until you're totally done. One algorithm that I haven't yet seen mentioned in this discussion is: shuffle the array of choices, pick the first k. If you're clever about it, this has some nice properties: you can stop shuffling after the first k, and if you want you can start reporting results imme…

I think the article discusses the fact that shuffling the entire initial set takes up way too much memory.

Re: Algorithm No One Knows About (2016)

#138
post #125
post #97

Some of the variable names used: i, j, t, qu1, S, n, N, U, X, y1, y2, V I know others have already commented on this but I think it's worth laying out all of the cryptic variables and asking: are some of these shorthand for well known math concepts that make it unnecessary to have a more descriptive name? I understand the use of temporary value holders like `i`, but have no clue what some of the others might be used…

The reason for naming the variables as they are seems to be to keep consistency with Vitter's paper [ http://www.ittc.ku.edu/~jsv/Papers/Vit87.RandomSampling.pdf ] Since the paper is really the primary documentation of the algorithm this makes perfect sense. Renaming the variables to be more meaningful to you would make it harder to compare to the paper, reducing the effectiveness of the paper as documentation and ma…

There's no reason to preserve bad notation from a 30year old paper.

Re: Algorithm No One Knows About (2016)

#140

https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

Exactly, just truncate the iteration to the first k elements. Need a hash table to get the modified values, so it breaks the "O(1) extra space" condition, but that condition is bullshit anyway, you're already using O(k) space to store the numbers you find, an extra hash table is also O(k) space. http://ideone.com/5uwqNO
Post reply on HN