Skip to content

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 scan…

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…

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…