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

#1 2012-12-11 16:29:49

Francesc4052
New Scratcher
Registered: 2012-12-11
Posts: 5

Need help with random number script

Hi everyone!
I've a big problem with a script who assigns 24 random numbers between 1 and 24 different from each others to black variables or if you don't understand a script who generate 24 random numbers between 1 and 24 including.

I don't found this script anywhere.
Someone can help me?

PS: Sorry for my english but i'm italian

Thanks in advance.
Bye

Offline

 

#2 2012-12-11 16:46:46

BetaSmozzick
Scratcher
Registered: 2012-02-25
Posts: 51

Re: Need help with random number script

Hmm. Not sure what you mean by black variables? Blank variables or what?

---

Assuming that you have the numbers 1-24 and each of them needs to be assigned to a variable.

You could have a list containing the numbers 1 - 24 (filled at the start of the program).

You then set a variable to random number between 1 and 24; the number that is chosen is the item in the list you set to a variable. You also delete that item from the list.

---

Something like this?

Link to Project: Random 24 Numbers

Last edited by BetaSmozzick (2012-12-11 16:51:25)

Offline

 

#3 2012-12-11 16:53:51

Francesc4052
New Scratcher
Registered: 2012-12-11
Posts: 5

Re: Need help with random number script

Oh sorry I meant to say Blank variables

Offline

 

#4 2012-12-11 16:55:10

BetaSmozzick
Scratcher
Registered: 2012-02-25
Posts: 51

Re: Need help with random number script

Ah, that's fine; I thought that might be the case.

The project I've linked seems like it would do what you need...not sure that 24 separate variables would work so well but if its essential then just after the code in the project set each variable equal to each item in the list.

Offline

 

#5 2012-12-11 17:04:50

Francesc4052
New Scratcher
Registered: 2012-12-11
Posts: 5

Re: Need help with random number script

Thanks for the answer but i've already tryed this script and it doesn't work! I eliminate the number after they have been assigned to a variable from the list but it happens an error and assigns equal numbers even variables also!
Do you know another methods?Or you have your own project? Maybe I'm wrong a few blocks, but I do not think.

Offline

 

#6 2012-12-11 17:09:07

BetaSmozzick
Scratcher
Registered: 2012-02-25
Posts: 51

Re: Need help with random number script

The project I linked was an example that I created for you and does randomly sort the numbers. I don't quite understand the problems your having with it? Could you try explaining that again?

---

Would you mind uploading your project so that I can try and see what's going wrong?

Last edited by BetaSmozzick (2012-12-11 17:11:03)

Offline

 

#7 2012-12-11 17:13:58

Francesc4052
New Scratcher
Registered: 2012-12-11
Posts: 5

Re: Need help with random number script

sorry I had not noticed the link, I downloaded it now, I don't understand the "Change to -1" in the second cycle ... my goal would be to bring 24 empty variables to 24 different random numbers, so that the numbers in the list are entered in 24 variables visible on the Stage

Offline

 

#8 2012-12-11 17:15:26

BetaSmozzick
Scratcher
Registered: 2012-02-25
Posts: 51

Re: Need help with random number script

No problem ^^

The change by -1 in the second cycle is because when you delete a number from the list the list becomes 1 item smaller and so any random number longer than the list would result in an error.

---

I thought that it might have to be displayed like that...in which case you would have to individually assign the values to the variables after the second list is filled.

Last edited by BetaSmozzick (2012-12-11 17:16:17)

Offline

 

#9 2012-12-11 17:17:52

Francesc4052
New Scratcher
Registered: 2012-12-11
Posts: 5

Re: Need help with random number script

Oh perfect. Thank you very much! I solved my problem  smile

Offline

 

#10 2012-12-11 17:19:49

BetaSmozzick
Scratcher
Registered: 2012-02-25
Posts: 51

Re: Need help with random number script

Awesome  big_smile  Glad it worked.

Offline

 

Board footer