Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The example usage of Java Random number and timer

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces "the example usage of Java random number and timer". In the daily operation, I believe that many people have doubts about the example usage of Java random number and timer. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "the example usage of Java random number and timer". Next, please follow the editor to study!

Produce a repeated random number of 90-100:

Public class RandomTest {public static void main (String [] args) {/ * * Math.random () method defaults to double type, so it needs to be cast to int * / int x = (int) (Math.random () * (100-90) + 90); / / (max-min+1) + min=min-max System.out.println (x);}}

Generate 90-100 random numbers that are not repeated:

Import java.util.HashSet;import java.util.Random;import java.util.Set;public class RandomTest {public static void main (String args []) {int max=100; / / maximum int min=90; / / minimum int count=max-min; / / Random number Random random = new Random (); Set set=new HashSet () / / only non-duplicated objects while (set.size ()) can be stored in the hashset container.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report