I’ve only been taking coding classes for a month, so I’m really sorry if I’m using some wrong/wacky constructions. I’m trying to make an addition game using two random numbers; r1 determines the number of terms in the addition problem, while r2 assigns a value to each of them. The scan…
Tag: random
How to generate the same pseudorandom numbers in Java as in Numpy (for the same seed)?
Is there any option to generate identical random numbers in Java like in Numpy random, when using same seed (e.g. 12345). In Numpy I get for code below output: 0.9296160928171479 In Java I get for code below output: 0.3618031071604718 I am comparing outputs of some methods in SciKit learn and my own library i…
Java SecureRandom declaration should be static class specific or can be instance specific
I am trying to use a SecureRandom to generate random numbers in my java project. But I am a little confused as how to keep my object for SecureRandom. Should it be a static class member. I dont intend to call this from outside. Below is my current implementation : Is this the correct way to use SecureRandom i…
Random search on an array of size N
I need help fixing my code below. I want to do a random search on an array of size N. Random search randomly picks up an integer from arr to compare. And the process repeats until the integer it is looking for is found (again it is remarked that the membership is guaranteed, otherwise random search obviously …
Is SecureRandom weaken when seed with Random?
Could a seed from java.util.Random for java.security.SecureRandom weaken the cryptographically strong random number generator? I saw this code and wonder why this is done in that specific way. From the documentation, the call of setSeed will never reduce randomness. So why is setSeed called anyway? public voi…
How can I intentionally create random floating point / decimal precision errors in java?
My goal is to generate random numbers that all have decimal precision errors. Here are some examples of types of numbers I would like to generate: Here are strategies I have tried. parseFloat(“4.01500000000000000001”); BigDecimal.valueOf(ThreadLocalRandom.current().nextFloat()).multiply(BigDecimal…
Java.util.Collection.Shuffle not producing random results when using a seeded Random
Given the following code: When I set numberOfItems to 4 and starting with a seed of 1, when dumping returnValue as Json I get: Incrementing seed, the fourth item in the list is always 3. Seed = 5: Seed = 10: Seed = 255: I am seeding Random as I need the result to be deterministic based on seed, but
Generate a deterministic random number from any number
From a number x, I want a function to get a random number y, uniformly distributed. For same x, the function should return same y. I tried: but apparently only the sequence of numbers provided by a seeded Random is uniformly distributed, not first values. Is this possible? Answer First, note that both int and…
Generate a random according to criteria [closed]
I have a JSON File (ArrayList) with some Restaurants and km(miles) from my Workplace to the Restaurant. The User can choose how far away the Restaurant should be (5km, 10km..) after that should the …
Finding Java.util.Random seed from bounded nextInt(int bound) results
Background I’ve been reading and trying to wrap my head around various questions/answers that relate to finding the seed from Java.util.Random given its output from nextInt(). The implementation of nextInt(int bound) is: The implementation of next(int bits) is: where the multiplier is 0x5DEECE66DL, the …