Skip to content
Advertisement

Tag: random

How do I return to the beginning of a while loop?

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 scanner checks the user’s input and based on that the

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 can enter an

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 void setSeed(long seed) Reseeds this random object, using the eight bytes contained in the

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.valueOf(ThreadLocalRandom.current().nextFloat())).doubleValue(); None of the things I tried have created even a single number similar to that which I am looking for. Answer Assuming that the exact values

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 float are 32bit datatypes in

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 addend is 0xBL, and the mask is (1L << 48) – 1. These are hexadecimal values

Advertisement