search

Home  >  Q&A  >  body text

java - 关于随机数生成Random的使用

为什么会报错,求大神教!!!(PS:想生成某个范围的随机数)
是不是Random对象初始化有错? 要怎么改才对啊?

伊谢尔伦伊谢尔伦2787 days ago824

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-17 17:59:51

    Your randoms are all null, and you will definitely get an error... You need to create a new Random object and assign it to random:

    Random random = new Random();
    // 其他代码

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:59:51

    Random random=new Random();

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:59:51

    You must have obsessive-compulsive disorder when writing code! For example, seeing warnings makes you feel uncomfortable. . . .

    reply
    0
  • Cancelreply