Random number without repeat

Its possible, show random number without repeat?

Yes, when you generate a random number check it against a list of previously added random numbers, if it is in the list, generate again until your new random number is not in the list, then add it to the list! Store the list in the tinydb, or tinywebDB / cloudDB if required across app users.

Try this-
image

@Alpha2020 - you need to add the new number to the list as well :wink:

2 Likes

Oh sorry, I will edit it

Sorry @ TIMAI2 I don't understand your answer. Tell me the details. Thank you.

@Alpha2020 blocks images says it all :slight_smile:

ok thanks,

https://imagnity.com/tutorials/app-inventor/shuffle-list-unique-random-numbers/

This algorithm is more didactic to do with blocks, but if you want an extension to do it directly...
com.KIO4_Random.aix (6.8 KB)
aleatorio1

Not Like This. I Have need show Single number. How Can I do This?

So set the random integer block like this-
random integer from 1 to 9

@Rafik30905 @RAFIK_905 Still using two account I see...

Oh Yes,
Sorry.....
One Use Laptop Others my Mobile. I remove One Account now.
Thank You.

@TIMAI2
Can you Help me? I Have need show Single Random number without repeat. How Can I do This?
Exm: I Select 1 to 10 Number for Random use.
When I Click button1, label 1 show single number from (1 to 10)
2nd click, 3rd click, 4th click......... 10th click = Label 1 show single number without repeat. when finessed random number output any Notice or others.

Use @Alpha2020's blocks, and add the variable "global RandomNumber" to your label text.

This technique depends on having a limit on the size of your random numbers, say 10...

  • init a global list remaining_randoms as all numbers from 1 to limit.
  • each button click, pick a random index from 1 to length of list remaining_randoms
    • display the selected item from list remaining_randoms using that index
    • remove the random index number from the remaining_randoms list
    • if the remaining_randoms list is an empty list, disable the button.

The OP wanted to finish after all the numbers had been selected. A more complete example on that basis:

Thank's Everyone, I solve My Problem, Try this Link System.
https://puravidaapps.com/snippets.php#2removerandom

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.