Get random element from set
See original GitHub issueWhat’s the most efficient way to implement something like RoaringBitmap.random()
?
For example, RoaringBitmap.first()
and RoaringBitmap.last()
return the smallest and largest elements… but how would you obtain a random element?
Thanks in advance!
Issue Analytics
- State:
- Created 6 years ago
- Comments:19 (10 by maintainers)
Top Results From Across the Web
Picking a random element from a set - java - Stack Overflow
toArray() on the supplied set. ToArray (in most if not all standard collection implementations) iterates over the entire collection, filling an array as...
Read more >How to Get Random Elements from Java HashSet?
Firstly convert HashSet into an array and then access the random element from it. · Then we will create an object of Random...
Read more >Select Random Element from Set in Python - CodeSpeedy
Select Random Element from Set in Python · random.choice(). This function retrieves a single element from the set. · random.choices() import random movie_list...
Read more >Java - get random element from set - Dirask
Iterate over the set and generate random number within size of the set. · Iterate over the elements of the set and keep...
Read more >Get a random element from a Set in Python | bobbyhadz
To get a random element from a `set`, use the `list()` class to convert the `set` to a list. Use the `random.choice()` method...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
What about
If you have a random pool, it is not going to be efficient to represent it solely as ranges, like you did. I think that the reason the ranges are efficient, is because of the strong statistical bias you have introduced.
That is, the minute you get close to a half empty interval, if you picked the elements at random, a set of ranges won’t be close to optimal storage-wise.