Home > Net >  Random that doesn’t repeat the last random
Random that doesn’t repeat the last random

Time:05-08

I am working on a simple program in Java swing that randomly selects a word from an array when you click a button. The issue is that I do not want to have the same thing generated after clicking the button again. For example, You click the button and it generates the word ‘donut’ from the array, you click again, and it generates donut again. I want to avoid generating the same thing directly after.

Here is the code:


import javax.swing.*;
import java.awt.*;
import java.util.Random;
import java.awt.event.*;

class Main implements ActionListener{
  JFrame f = new JFrame("ℂ           
  • Related