How “truly random” is set.pop()
in #Python. The docs say: »Remove […] an arbitrary element from the set.«
How arbitrary is arbitrary? I guess the elements are arranged in the set’s tree structure by their hash(), so it all depends on that hash function, right?
I want to randomly remove half of the entries of a set.
[#] This seems more correct 🧑🏫 s = {el for el in s if getrandbits(1)} [#] But this is a mu faster 🥺 for _ in range(len(s) // 2): s.pop()
=> More informations about this toot | View the thread | More toots from fabian@floss.social
=> View python tag This content has been proxied by September (ba2dc).Proxy Information
text/gemini