Getting a random value from an array

后端 未结 3 1836
Happy的楠姐
Happy的楠姐 2021-01-28 07:38

I have a simple app that generates facts. I would like to incorporate a function that generates a random fact instead of incrementing of decrementing.

My array looks lik

3条回答
  •  春和景丽
    2021-01-28 07:55

    Try this also

    private Integer a = 0;
    public String randomButton() {
      Random random = new Random();
      a = random.nextInt(facts.length);
    }
    String factNumber = facts.a;
    

提交回复
热议问题