You are not logged in. Your edit will be placed in a queue until it is peer reviewed.
We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.
Required fields*
-
"(barring an extremely unlikely accident where Math.random() returns the same value twice in a row)." Two things here: 1. it doesn't have to be in a row. If you get "a", "b", "a" as keys, that still clashes, without being in a row. 2. Depending on the range of values, it's not that unlikely due to the birthday paradox. With a range of 15 possible random values and calculating a random value 3 times, the chance for a collision is about 20%. If we go with 4 calculations, that's 35% chance.VLAZ– VLAZ2026-02-05 13:02:30 +00:00Commented Feb 5 at 13:02
-
@VLAZ True - I was considering the strict case here where there are only 2 properties in the object. No doubt a scenario will arise where there are more. And the problem is exacerbated by rounding the values, greatly decreasing the possible outcomes that are passed to the object - Math.random generates a far larger possible number of values by itself. However, the OP did indicate that this isn't the real function, so probably it's a moot point for them in their actual workADyson– ADyson2026-02-05 13:27:25 +00:00Commented Feb 5 at 13:27
-
@VLAZ In my actual use case, there absolutely can and will be far more than two items. Definitely hundreds, possibly thousands; on an off chance, tens of thousands, though at that point we'd likely be looking to branch some of our data into something like SQL. They're all being handled on a procedural basis, so you don't really need to keep track of all that - but in the event you need to trace the stack down for bugfixing, or perhaps on a rare case access a part of the datastructure directly to modify it (think useRef) you'll be able to.Neokythera– Neokythera2026-02-05 13:32:55 +00:00Commented Feb 5 at 13:32
-
1Instead of random numbers, why not just increment a counter?Barmar– Barmar2026-02-05 16:48:41 +00:00Commented Feb 5 at 16:48
-
@Barmar That might be a question to ask the OP, not me :-)ADyson– ADyson2026-02-05 18:24:09 +00:00Commented Feb 5 at 18:24
|
Show 3 more comments
How to Edit
- Correct minor typos or mistakes
- Clarify meaning without changing it
- Add related resources or links
- Always respect the author’s intent
- Don’t use edits to reply to the author
How to Format
-
create code fences with backticks ` or tildes ~
```
like so
``` -
add language identifier to highlight code
```python
def function(foo):
print(foo)
``` - put returns between paragraphs
- for linebreak add 2 spaces at end
- _italic_ or **bold**
- indent code by 4 spaces
- backtick escapes
`like _so_` - quote by placing > at start of line
- to make links (use https whenever possible)
<https://example.com>[example](https://example.com)<a href="https://example.com">example</a>
How to Tag
A tag is a keyword or label that categorizes your question with other, similar questions. Choose one or more (up to 5) tags that will help answerers to find and interpret your question.
- complete the sentence: my question is about...
- use tags that describe things or concepts that are essential, not incidental to your question
- favor using existing popular tags
- read the descriptions that appear below the tag
If your question is primarily about a topic for which you can't find a tag:
- combine multiple words into single-words with hyphens (e.g. python-3.x), up to a maximum of 35 characters
- creating new tags is a privilege; if you can't yet create a tag you need, then post this question without it, then ask the community to create it for you
lang-js