请我在android studio活动中有两个TextView,那些Text有一个随机数我需要多次获得结果,但是得到随机数,同一个数字的副本出现,我怎么能阻止?这是我的代码:
我以这种方式将随机分配给TextView:
object : CountDownTimer(timeToEndTwo, countDownForRandomTwo) {
override fun onTick(millisUntilFinished: Long) {
num1.text = randomNumber().toString()
num2.text = randomNumber().toString()
}
然后比较: if(Integer.parseInt(num1.text.toString())* Integer.parseInt(num2.text.toString()) == Integer.parseInt(result.text.toString())){ Toast.makeText(applicationContext," right",Toast.LENGTH_LONG).show()
和我用来生成随机数的函数是:
private fun randomNumber():Int{
val rand = Random();
return rand.nextInt(10) +1
}