[Solved] How can i Generate a random number without repeat

i am creating app which take form local Db the Row randomly

the the row can be repeated many times Because The random Number is repeatd i want to choose the same nuber Just one Time

1 Like

Hi, @3bdoamir1! :wave:
Welcome to our community! :blush:

For this, you would need to store the used numbers in a list, and everytime generating a new random no., only accept it if itā€™s not in the used numbers list.


First try applying this method yourselves, and tell us the result. If you stuck, weā€™ll help you out :star2:

Good Luck! :tada:
Thanks! :blush:

2 Likes

To piggyback off @kartik14, I would get a super long list Of integers from random.org

2 Likes

thanks for answer i did it already but i dont understand list i am new

cqn You describe more about your app? Iā€™m not sure I understand what you are trying to do after rereading everything. Do you want the row from localDB to be deleted? Or just not used until all rows have been used at least once?

If thatā€™s the case there is a special block just for that.

In my quiz app, I take all of the questions from local dB, put them into an ā€˜appā€™ type variable I call tempList. Then as my quiz steps through each question, instead of getting it from the localDB, I pull the question from var ā€˜app tempListā€™. I use the blue list block that says ā€œget and remove #ā€. Then the app ends when ā€˜app tempList is empty.

The next time the user want to take that quiz to study, all or the questions are reloaded into ā€˜app tempListā€™ and the process starts over again

I just to make a random number say from 1 to 100 not repeated every btn click like 18 btn click the variable becom 16 >>> btn click the variable become 98 btn click the variable become 15
i want the variable change every click not( 18 >16>> then 18 again)

Does that happen when you use the random integer block?

The thing about randomness is that your odds that you will get the same number two times in a row are just as likely as getting a different number. are just as likely to get the same number as any other number.

1 Like

I Know its Just example >> what i want make the variable a number and never repeat again when i click btn i want like that it i press btn the variable change every click like random number from 1 to 10 (1.4.8.6.5.3.2.,10,9,7) no repeat numbers every btn change avariable to new number

that what i want to do but i cant can u help me pls

1 Like

Hi, @3bdoamir1! :wave:

Try these blocks -

image

Thanks! :blush:

2 Likes

My browser crush when i try it
the link
https://x.thunkable.com/copy/d3168f449d89b1426a6302d4084d7222

Hi, @3bdoamir1! :wave:

Very sorry to inform, I had mistake in my code :sweat:

Please try this one, this works brilliantly for me -

image

Apologies :slightly_smiling_face:
Thanks! :blush:

2 Likes

This task has been solved more than once on the forum.

  1. Upload all data from the source to the list
  2. Get the number of rows in the list
  3. Generate a random index of an element from this range
  4. Get the row element by this index
  5. Delete a list item by this index

Repeat steps 2-5 if the list is not empty

2 Likes

i want to make iq test 200

image

thats really what i want but try it with 5 numbers rather than 100
u will find the number repeat

sorry i am new >> i want to do iq test 30 qustion from 200(after 30 its end ) every time you answer its replace questions and answers all done >> now when i make it choose questions randomly it may repeat some qeustions i want to make a variable with every btn click it change to new value (not repeat any old ) can u help me with blocks to make random variable every click no repeat

Search the forum. This has been solved before.

I found extension . aia i cant use them or a written and i am new so i cant do it co u help me

All you need to do is create a list with the numbers 1-100 (or however many records you have).

Select a number at random from it and remove it from the list.

This way every number will be unique.

2 Likes

i tried but i dont understand list


it doesnt work

ā€¦

it doesnt work

Check it

ŠøŠ·Š¾Š±Ń€Š°Š¶ŠµŠ½ŠøŠµ

3 Likes