I wrote this Java Application which is used to extract a random value from those entered in the JTextFields after starting a counter. Compiles and gives no errors, but the (“” +randomElement) value is not displayed. I created the randomElement property inside the TimerListener class in the actionPerformed() method which starts the counter. At the end of the count the
Tag: random
Why is my random number generator becoming an unused assignment when using it to input values for 2d array?
I have been making a basic game of battleship and to get the CPU to choose ship locations on a 2d array I am making two random number generators to pick values from 1 to 8 on a separate method. For some reason, the random generators show up as unused and I don’t know why. so far this is what
Randomly getting value with percentage of chance in Java
I would like to be able to return (and in our case, for the example, display) an item of an enumeration, according to a certain predefined percentage of chance for each item. An illustration in code of this enumeration just below : Also, these items will be stored in a List. Namely that, as in this example, two items can
How to get a random multiple of a given number within a range
I’m making a program in which a JPanel is created with a random RGB value and the user has to use buttons to match the color in another JPanel. I want the random R, G, and B values to be multiples of …
Rounding in Java using Math.random()
Suppose I write then one would obtain and output of x in [0, 4.9…]. But upon casting it as an integer, the result I continuously see (in my course) is [0, 4]. My question is how we are defining the rounding function; I am familiar with the floor function, and the floor of 4.9… is precisely 5 due to there
Is there a Java 8 implementation of a random generator supporting NIST standards?
I am trying to securely generate random numbers. It must support NIST standards, that is NIST SP 800-90A, SP 800-90B, SP 800-90C. I’ve read that Java 9 has an implementation of SecureRandom supporting such standards. My question is: is there an implementation supporting these standards in Java 8 (I am using Android)? Ideally I would like it to be built-in
Anylogic: Use individual RandomNumberGenerator for each ressource
We are working on a simulation of a production chain of six machines connected in a series. For all of them, we need failure times etc. which are distributed differently. I am looking for a way to implement an individual RNG for each of the resources used. We need six different RNGs. Unfortunately, we struggle to understand how to implement
How I can make my program generate a new random number?
So I tried closing the window and reopening it afterwards so the whole program would start from the beginning. That didn’t work. Neither does Revalidating the frame (f.revalidate(), f.repaint()).. I’ve tried looping the if-functions with a while loop, setting the boolean to false when the number has been guessed. But that just resulted in an endless loop of testing if
Can I use a randomly generated number as a parameter to a method in Java?
So I’m very new to Java so this question might have a pretty simple answer. I’m trying to create a Magic8 ball program and I want the fortune to depend on the randomly generated number, but it’s …
Generating Random Number of Characters
I have to create a program that reads in the number of character to be printed, and it will print random chars (a-z, A-Z, 0-9 and characters like !, &, $, etc). And the first character to be printed cannot be a number (0-9). So an example output would be like: Length of Variable? 20 a5fTnO$akP_a12BahsiO This is what I