ganesh_6's blog

By ganesh_6, history, 2 months ago,

What is the alternative to mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); in c++ for Java? Tagging users who use Java for Problem Solving

• -20

 » 2 months ago, # | ← Rev. 2 →   0 This is the topic i found no one has made a blog on. I wanted to know how Problem Solvers using Java handling this. I had to make this because using manual hashing made me go through hash collision, while i can see legends like tourist using rng to generate random numbers for every number to solve A2 problem in round2 2022 Facebook Hackercup https://codeforces.com/blog/entry/107302#comment-956895. I don't find anything like that in Java. Please help me. Thanks! PS: Please Don't downvote, better answer or suggest someone who can answer
 » 2 months ago, # | ← Rev. 5 →   -8 well, Java's random number generator from java.util is quite uniform so you can use that. You can use System.currentTimeMillis() as a seed if you want the seed to change everytime you run the code.I still think you could've found this with a simple search on google, though. No need to ping the Java users (and tourist), too.upd: I found that you pinged them twice, and thats just too excessive. Please refrain from pinging people publicly unless you ABSOLUTELY (yes, most of the time you don't) have to. I learnt this the hard way and I don't want you to do the same. If you need help from them you can kindly ask them via private message.
•  » » 2 months ago, # ^ | ← Rev. 2 →   -10 I tried that and it did not work, it gives different value every time as output. SO i asked here. https://pastebin.com/zYPUTvz1
•  » » » 2 months ago, # ^ | ← Rev. 2 →   +3 It using different values every time is the entire point of what people are trying to do with seeding their random number generator with the time. People do that so that others can't hack them with an adversarial test cases where they get unlucky with the random numbers they choose. In order for someone to hack you, they'd have to correctly guess the millisecond that your code would run. (you can seed it off nanotime if you want them to have to guess the nanosecond, which is practically impossible)To answer your question, new Random() in java defaults to being based of the clock, which means it'll have this different-every-time behavior by default. This is the equivalent.If you don't want it be be different every time, you can seed your Random off a constant like Random rand = new Random(5);.
•  » » » » 2 months ago, # ^ |   0 Yeah, but that still gives WA for A2. https://pastebin.com/zYPUTvz1Could you correct me or provide a code editorial in FB HC page. I appreciate your time in answering my question anyway.
•  » » » » » 2 months ago, # ^ |   0 Code editorial for which problem?
•  » » » » » » 2 months ago, # ^ |   0 Facebook Hackercup Round 2 A2. This discussion is all about that. I thought u got that.
•  » » » » » » 2 months ago, # ^ |   0 Could you please provide code editorial (Java) or any language so that the algorithm used can be implemented in any language. THanks