0

I need to create complete random numbers using a seed in JavaScript. I'm not using the built-in Math.random(), but rather something else that can take a seed and generate a random number based on that.

This solution is supposed to serve a situation in which two users log in at the same time to a website (it happens A LOT, and I'm getting a lot of users with identical IDs because of it). Math.random() isn't working for me, and I can't use timestamps because these also don't provide an accurate number (they're not being sampled every MS). I also don't want to use any ajax call in order to get an IP or something similar.

Is there anything anyone can think of that's either unique, or might be rare enough to use to create a good seed?

**EDIT: ** This is NOT a duplicate of the GUID generation question, because that one is still using Math.random(). I can't use that function anywhere in my code. I sometime have thousands of hits at more-or-less the exact same moment, and that's what screws up the random. It's also the reason why I need to find some attribute I can use as a seed.

Community
  • 1
  • 1
Luoruize
  • 579
  • 2
  • 7
  • 25
  • 1
    http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript?rq=1 – j08691 Jun 17 '14 at 13:26
  • Possible duplicate: http://stackoverflow.com/questions/424292/seedable-javascript-random-number-generator – thedude Jun 17 '14 at 13:28
  • 1
    I do not think it's a duplicate. There they're using Math.random() and he doesn't want to use it. That said...I'd investigate how he can get "a lot" of duplicates using random numbers generator. – Adriano Repetti Jun 17 '14 at 13:28
  • 1
    @AdrianoRepetti It doesn't really matter if the duplicate is using `Math.random` or not. The point is that the OP needs a way to generate a unique ID...he was just doing it the wrong way (if they aren't turning out unique). The duplicate provides a way to generate unique values – Ian Jun 17 '14 at 13:30
  • I'm actually using one of the functions mentioned on that page to create GUIDs, and still - when there's heavy traffic and I get thousands of hits on the website per second, it slips and gives me identical GUIDs. – Luoruize Jun 17 '14 at 13:39
  • Possible Duplicate: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript – user3032973 Jun 17 '14 at 14:02
  • Same as before - if it's using Math.random - it's not working for me. – Luoruize Jun 17 '14 at 14:24
  • There are several answers in the duplicate that should work for you. This seems to be a very well understood problem with solutions. – JasonMArcher Jul 07 '14 at 20:34

0 Answers0