How can I prevent doubles?

I thought I programmed this app to avoid showing the same number twice. During testing, I saw duplicates, multiple times. How can I prevent doubles?

I recorded some testing:https://youtu.be/2Zts7CzLkZc

https://puravidaapps.com/snippets.php#2removerandom

from FAQ Section: Lists

1 Like

I appreciate you linking me to the concept of the List of integers. I thought there might have been some way to set the “Seed” of the random selection.

Is this something that the Devs should know about? I programmed the app to check against the previous selection of the random integer. But, it’s not working correctly.
This is the recording of the testing. It’s not public, it is
Unlisted :slight_smile:
https://youtu.be/2Zts7CzLkZc


Please export your project and post it here.

WinningNumbers.aia (70.2 KB)

 It looks like the List concept would work.

I think it is best to use List Blocks, but if you want an extension you can check:

https://groups.google.com/forum/#!category-topic/mitappinventortest/app-inventor-extensions/59KuusuzAiU

Here is a critical component you can use …

randoms randoms_in_range.aia (3.1 KB)

Your app can also benefit from generic (Any Label) blocks and by grouping the Labels for each lottery type into a list, which can be traversed in parallel to the list of randoms matching that length and limit.
That would collapse the number of blocks in your app by a factor of 2 or 3 (give or take lotteries with special rules.)

Using generics and component lists can shrink your code …
WinningNumbersV2.aia (61.7 KB)

when Button1PBV2 Click randoms global PBLabels global NLLabels when Button1NLV2 click

I only did this for two lotteries, to show the pattern.
The parts of the blocks that look like combs can also be collapsed using this technique.

In case ant of you are wondering how I ended up solving this issue in my app. I did not use the list at all. After I really thought about preventing duplicate numbers in a place where I am certain that it happpens, I just used the same blocks. The same blocks that I originally used, I just used them later in the sequence, or is it calledmethod? I will attach an image of what I did. Because I’ve been testing it, and I see NO doubles anymore. Thank you all, anyway.

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