• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
戈瑾
博客园    首页    新随笔    联系   管理    订阅  订阅
随机数

要求:编写一个方法,使用以上算法生成指定数目(比如1000个)的随机整数。

复制代码
 1 import java.util.Scanner;
 2 public class Test1
 3 {
 4     public static void RandomS(int n,int x) {
 5         int m[]=new int[n+1];
 6         m[0]=x;
 7         for(int i=1;i<=n;i++) {
 8             m[i]=(m[i-1]*16807)%Integer.MAX_VALUE;
 9             System.out.println(m[i]+"\t");
10         }
11     }
12     public static void main(String[] args) 
13     {
14         Scanner in=new Scanner(System.in);
15         System.out.print("请输入要生成随机数的数目:");
16         int n=in.nextInt();
17         System.out.print("请输入种子数:");
18         int x=in.nextInt();
19         RandomS(n,x);
20     }
21 }
复制代码

posted on 2020-10-10 08:22  戈瑾  阅读(106)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3