This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-02-27 15:24:16

charles2004
New Scratcher
Registered: 2013-02-27
Posts: 2

random numbers without repeating

hello,
can any one suggest a way of producing a set of 13 random numbers but without repeating any ?
trying to write a times table multiplication test
to go through the numbers 0 to 12 but in a random order but each number only once ?
thankyou

Offline

 

#2 2013-02-27 15:27:21

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: random numbers without repeating

Try using a list, and deleting the item from the list whenever it is chosen.

Offline

 

#3 2013-02-27 16:24:11

charles2004
New Scratcher
Registered: 2013-02-27
Posts: 2

Re: random numbers without repeating

many thanks will give it a try, what would that look like in a program ?

not sure how to delete from list

Offline

 

#4 2013-02-27 19:49:12

lalala3
Scratcher
Registered: 2008-10-03
Posts: 100+

Re: random numbers without repeating

charles2004 wrote:

many thanks will give it a try, what would that look like in a program ?

not sure how to delete from list

Look around in the Variables section of the editor and you'll find the block you need to delete items from a list.


http://img515.imageshack.us/img515/9374/signature2nt.png

Offline

 

#5 2013-02-28 16:18:03

mathfreak231
Scratcher
Registered: 2012-10-24
Posts: 80

Re: random numbers without repeating

Try this script (you need three lists: one that has the numbers you want, and two empty; and two variables):

set [iterator v] to [0] //Reset the iterator
repeat (length of [all_numbers v])
change [iterator v] by (1)
add (item (iterator) of [all_numbers v]) to [selection v] //Copying the numbers over to another list
end
repeat (length of [selection v])
set [selected v] to (pick random (1) to (length of [selection v])) //Pick a random number
add (item (selected) of [selection v]) to [random_order_list v] //Add the corresponding item to the new list
delete (selected) of [selection v]
end
Hope this works!

Last edited by mathfreak231 (2013-02-28 16:19:02)


~This sig is false~
I'm on teh wiki!

Offline

 

Board footer