How to Disable Random Numbers in Java

Java includes a class that generates random numbers. You use this function to disable random numbered selections — useful for games or functions in which you want to randomly show the user a record, such as a predictive dialer for a customer service application. You use the random-number-generator class to pass to the function that disables your Java controls.

Instructions

    • 1

      Open your Java programming editor and open the Java app project you want to edit. Open the source code file you want to use to create the random number.

    • 2

      Initialize the random generator class. Initialization lets you set up the generator to return a number. Add the following code to the file:

      Random random = new Random();

    • 3

      Generate a number. You specify the range in which you want to generate a number. The range is from zero to a positive integer number. For instance, the following code generates a number between zero and five:

      int number = random.nextInt(5);

    • 4

      Pass the integer to the function that disables the control. For instance, the following code passes the random number to the "DisableControl" function:

      DisableControl(5);

Related Searches:

References

Comments

Related Ads

Featured