@lukeshiru Thanks for your comment! Never used generators in javascript - very interesting! Regarding your "simpler approaches": The first one (more or less) equals No. 2 and the second (more or less) equals No. 3 in the article from Graham Cox referenced in my article. Both do very well if and only if the range [min, max] is not "too large". Citation from Graham Cox article:
However, what if, instead, we want to be able to generate any 32-bit integer? This would mean that we need a single 32-bit counter and an array with one entry for every possible 32-bit integer. This means we need (2^32 + 1)*4 bytes of memory, which is ~16GB.
So the memory consumption is enormous in this case. In contrast the algorithm proposed by me only needs some 100 bytes in this case due to its logarithmic space complexity.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
@lukeshiru Thanks for your comment! Never used generators in javascript - very interesting! Regarding your "simpler approaches": The first one (more or less) equals No. 2 and the second (more or less) equals No. 3 in the article from Graham Cox referenced in my article. Both do very well if and only if the range
[min, max]is not "too large". Citation from Graham Cox article:So the memory consumption is enormous in this case. In contrast the algorithm proposed by me only needs some 100 bytes in this case due to its logarithmic space complexity.