Check RoomDb and Array if they don't contain the a number add it to the array

Viewed 19

I have a random number being generated,

this number is then assigned a random number

number = (1..NumberMax).random()

the number should cycle until the number is not saved within the RoomDb which i am checking with this function

@Query("SELECT EXISTS(SELECT * FROM Number_Table WHERE NumberID IN(:randomNumberID))")
        fun hasItem(randomNumberID: Int):Boolean

I have a repeat function to set and add the number to the array but also changing the number if it is contained in the roomDb or in array

repeat(5){
number = (1..ruleAmount.toInt()).random()

 while(addUserNumber.CheckUserNumberRule(number) == true && numberarray.contains(number) {
      number = (1..NumberMax).random()
      }
numberarray.add(number)

}

my issue is that the numbers I get would be the same as the numbers as I have saved in RoomDb, I am unsure if there's a better way to loop through to check if it is in the RoomDb and if it is in the array and if it is in either change the number until its not in either

0 Answers
Related