# Get random number without repeating

how to get random numbers without repeating.

I tried something like this but numbers are repeating

Result

2 Likes

(Updated/Edited) - I posted some blocks without testing and those blocks are not working, sorry for that. I edited this post.
This works perfectlyâ€¦

Mark as Solution if found helpfulâ€¦

2 Likes

Did you even try your code, as both looks weird to meâ€¦

1 Like

I tried this method in my real project and itâ€™s not working.

I used Method 2 in my random generator app for remove used letters for scattergories.

1 Like

@sonumohammad333 Your 1st method looks strangeâ€‹, and I just tested the second method, it is not working.

It will only work at first removal and on a couple of them it will remove the wrong index number and in the end it will show wrong list length

2 Likes

What should i do next.

3 Likes

Procedure to generate lists of numbers with these options:

Minimum
Maximum
How many numbers
Repeat or unique numbers
Sorted or unsorted
Sort order ascending or descending

4 Likes

What do i need to change in this blocks ?

What you are doing wrong is selecting random numbers from a fixed range (example 1 to 10, always).

You need to change that range every time a number is selected to create a â€śpoolâ€ť of possible numbers. Example : Pool is 1,2,3,4,5,6,7,8,9,10. If 4 is selected, then remove it from the pool and next time it will not be possible to select it again.

We all showed you up there how to do that. You will have to adapt it to your project.

2 Likes

I edited my post. Now it works perfectly.

1 Like

project.aia (12.2 KB)

I am unable to adapt it according to my project,here is my file.

When that happens, it means you have to start the whole procedure from scratch. I would recommend that, since your procedure for selecting random numbers is not what you really need.

1 Like

I am creating a quiz app with the help of quize extension, and I want that when the answer to the question arises from this extension, I want to show the numbers around that answer in four buttons, of which 1 will be the correct answer which will be generated by the extension and the remaining 3 options will be the numbers around that answer.

you might want to look into this App Inventor Tutorials and Examples: Advanced Features | Pura Vida Apps
Taifun

1 Like

you might want to look into this App Inventor Tutorials and Examples: Advanced Features | Pura Vida Apps
[/quote]

I generated 4 possible answers, Now I have to show 4 options without repeating numbers, i am confused how can i do like this.