我是靠谱客的博主 体贴小霸王,这篇文章主要介绍随机数---抽奖,现在分享给大家,希望可以做个参考。

从 1 - 20里面随机抽取10个不同的数

package com.classmassage.cn.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Sjs {

    public static void main(String[] args) {
        List<Integer> nums = new ArrayList<>();
        for (int i = 1; i <= 20; i++){
            nums.add(i);
        }
        int math = 20;
        List<Integer> sysout = new ArrayList<>();
        for(int j = 0; j < 10; j++){
            Random r = new Random();
            int sjs = r.nextInt(math - j);
            sysout.add(nums.get(sjs));
            nums.remove(sjs);
        }
        for (int s = 0; s < 10; s++){
            System.out.println(sysout.get(s));

        }


    }
}

最后

以上就是体贴小霸王最近收集整理的关于随机数---抽奖的全部内容,更多相关随机数---抽奖内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(172)

评论列表共有 0 条评论

立即
投稿
返回
顶部