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

#1 2009-09-25 17:47:32

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

How do i have the numbers 1 to 10 in random order and not repeat any

Do you guys know how to have the numbers 1 to 10 appear in a random order and not repeat any of the numbers. For instance a code that puts the numbers like this : 8,3,6,2,1,10,9,4,5,7, and each time I try it out the numbers are different

Offline

 

#2 2009-09-25 17:55:28

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Here is one way to do it (in text, I'm too lazy to do scripts):

1. Create a list variable called MyList
2. Create a regular variable called MyValue
3. Create a regluar variable called MyIndex

This script will set up your list:

When Flag Pressed
Delete All of MyList
Set MyValue to 1
Repeat 10 times-----------
| Add MyValue to MyList
| Change MyValue by 1
----------------------------------

This script should be called when you want a number:

When I receive GetANumber
Set MyIndex to (Random 1 to Length of MyList)
Set MyValue to (Item MyIndex of MyList)
Delete item MyIndex of MyList

At this point, the variable MyValue has a random value from 1 to 10.  You can call it 10 times and never get a repeat.  The way you call this is to use the "Broadcast GetANumber and wait" block.

This is exactly how I handle a deck of cards in all of my various card games.

Hope this helps.

Last edited by BoltBait (2009-09-25 17:57:52)


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#3 2009-09-25 18:02:58

The-Whiz
Scratcher
Registered: 2007-07-09
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

BoltBait wrote:

Here is one way to do it (in text, I'm too lazy to do scripts):

1. Create a list variable called MyList
2. Create a regular variable called MyValue
3. Create a regluar variable called MyIndex

This script will set up your list:

When Flag Pressed
Delete All of MyList
Set MyValue to 1
Repeat 10 times-----------
| Add MyValue to MyList
| Change MyValue by 1
----------------------------------

This script should be called when you want a number:

When GetANumber is received
Set MyIndex to Random 1 to Length of MyList
Set MyValue to Item MyIndex of MyList
Delete item MyIndex of MyList

At this point, the variable MyValue has a random value from 1 to 10.  You can call it 10 times and never get a repeat.

This is exactly how I handle a deck of cards in all of my various card games.

Hope this helps.

Too put it in block terms:
<when green flag clicked>
[delete all of [My List]]
<set{ My value }to( 1
<repeat( 10
[add (My Value) to [My List]]
<change{ My Value }by( 1
<end>

<when I receive[ Get A Number
<set{ My Index }to( <pick random( 1 )to( length of [My List]
<set{ My Value }to( item (My Index) of [My List]
[Delete (My Index) of [My List)]

Last edited by The-Whiz (2009-09-25 18:03:28)

Offline

 

#4 2009-09-26 14:18:51

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

Re: How do i have the numbers 1 to 10 in random order and not repeat any

sorry, but the numbers still repeat when i try them out. need a clearer explaination

Offline

 

#5 2009-09-26 14:56:19

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Hmm...

[blocks]
<when green flag clicked>
[Delete all of List]
<repeat( 10 )>
<set{ Number }to( <pick random( 1 )to( 10 )>
<if>[List contains <{ Number }> ]
(Keep blank here.)
<else>
[Add <{ Number }> to List]
<end>
[/blocks]

Hope that helps... I'll post a project later.

Offline

 

#6 2009-09-26 15:33:03

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Project, some stuff has been changed from the script above, but it still works.  smile  http://scratch.mit.edu/projects/Magnie/695598

Offline

 

#7 2009-09-26 15:37:20

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

Re: How do i have the numbers 1 to 10 in random order and not repeat any

magnie is there a way i can send you this project so you can fix the issue i'm having. basically what i want is to have 10 questions appear in a random order each time you retry it. I have everything already finished and the questions are a different sprite and they correspond to a number from 1 to 10. I'm not an expert on scratch so I'm pretty sure you won't have trouble understanding the codes I wrote for this project. Please can you help me or anyone else who wants to have a look through at my project, give me your email address. please i am desperate.  sad

Offline

 

#8 2009-09-26 15:42:01

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Why can't you just post it? *sigh* I can't give you any Email on the forums, so you need to create a gallery.

Last edited by Magnie (2009-09-26 15:42:43)

Offline

 

#9 2009-09-26 15:43:46

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Ok i'll post it

Offline

 

#10 2009-09-26 15:45:19

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Thanks.  smile

Offline

 

#11 2009-09-26 15:48:57

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Here you go: Just download it and see if you can do it.
http://scratch.mit.edu/projects/legendzkillar/695626

Offline

 

#12 2009-09-26 15:55:59

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Yeah, got it, it's gona take some time to get it to work. (Needs to think through your programming to understand it.  wink  )

Offline

 

#13 2009-09-26 16:02:08

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Lol, you can take all the time you want. I really hope your post doesn't contain this message: "I couldn't do it, sorry", lol anyway just do your best, your projects are impressive btw.

Offline

 

#14 2009-09-26 16:06:25

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Thanks! It will take me a day or two, or just 30 minutes. I think I found what you're doing but I don't know the answers to these questions. xD

Offline

 

#15 2009-09-26 16:17:10

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Knowing the answers would actually help a lot, all I need to do is test it a few times and it's ready.  big_smile

Offline

 

#16 2009-09-26 16:18:47

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

Re: How do i have the numbers 1 to 10 in random order and not repeat any

you wants answers I'll give you the answers  smile
B, A, C, A, B, A, D, A, B, D

Offline

 

#17 2009-09-26 16:21:23

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Lol thanks!

Offline

 

#18 2009-09-26 16:26:45

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Okay, I have one glitch I've noticed, the first 3-4 questions don't say correct or incorrect. (They don't say ANYTHING) and sometimes when you get the correct answer it will say That's Correct! then it will say The correct answer is [Letter]! <- It says that RIGHT after it says the correct answer. I'll dig deeper into the code and see where it's broken.  smile

Offline

 

#19 2009-09-26 16:31:19

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

Re: How do i have the numbers 1 to 10 in random order and not repeat any

One thing if you haven't noticed there are codes in the background(stage) sprite also. Those codes are pretty important. They have the answers set out in numbers, A= 1, B=2..etc I think if you have the questions in random order then you have to find a way to have the answers follow the right questions.

Offline

 

#20 2009-09-26 16:33:16

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

I can't be on anymore right now, Hopefully on Monday or tonight I'll get this done, I'll upload the project so far. http://scratch.mit.edu/projects/Magnie/695674 <- There's the project so far, but not done.

Offline

 

#21 2009-09-26 16:37:51

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

Re: How do i have the numbers 1 to 10 in random order and not repeat any

It would be great if it was done by sunday, but monday however will lead to my death. Unfortunately, it needs to be done before monday, if you can finish in sunday you will still be awesome.

Offline

 

#22 2009-09-26 18:17:19

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Yeah, that's what I thought, but I think it's done. It's just I can't go on Sunday, so that's why I said Monday. But here's the project: http://scratch.mit.edu/projects/Magnie/695787

Offline

 

#23 2009-09-26 22:25:26

legendzkillar
Scratcher
Registered: 2009-09-24
Posts: 15

Re: How do i have the numbers 1 to 10 in random order and not repeat any

ohh so close, but unfortunately the answers aren't matching with the questions. even when i answer it right it says wrong. I might just get rid of the whole "the correct answer is..." to make it simpler. Your help would be nice also, even on monday.

Offline

 

#24 2009-09-26 23:16:01

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Hmm... Yeah, I was gona say why have it say "Correct!' or 'Incorrect!' but does it say the right amount correctly at the end?

Offline

 

#25 2009-09-27 00:59:05

Digimath
Scratcher
Registered: 2007-07-07
Posts: 100+

Re: How do i have the numbers 1 to 10 in random order and not repeat any

Hopefully my modified version of Magnie’s project based on your project is what you want.
http://scratch.mit.edu/projects/DigimathFixit/696214

The fonts are not the same as your original project but keeping fonts the same between re-mixed projects appears to be a problem in Scratch.


I've updated my text adventure game.
Colossal Cave 150http://scratch.mit.edu/static/projects/Digimath/3003787_sm.png

Offline

 

Board footer