Random Numbers with the restriction that each number is shown only once?

I’d like to make a vocabulary game with the merge cube. For that I need a random number (which is in that case a random word). However, each number (or word) should only appear once and not a second time. Unfortunately, I am pretty stuck and some help would be greatly appreciated :wink:

Here’s the link to what I did. It is just a basic construction. The red word on floating panels are the words which the student has to find on the cube (which is also red but this is just done for testing matters)

Hi @Asmodean,

you can generate array of numbers, that represents your questions, and then shuffle it. So you will have a random order and every question appear once.

//number of your questions
let N = 5;

//create an array
for (var ar=[],i=0;i<N;++i) ar[i]=i;

//shuffle it
for (var i = N - 1; i > 0; i--) {
   var j = Math.floor(Math.random() * (i + 1));
   var temp = array[i];
   array[i] = array[j];
   array[j] = temp;
}

//now the array has numbers from 0 to N in a random order

Hope that helps

Thanks very much for that super fast reply, Nikolay.

Is that also possible to replicate with Coblocks somehow because I am really sucky when it comes to real coding :frowning:

Sure, I created a CoSpace for you with the objects movement in random order.


You can remix it, see the code and copy parts of it into yours project.
Here is the code snapshot from it:

The num variable stores the quantity of objects (questions in your project).
The object variable is a list of them.
I created additional list - listNum with numbers from 0 to (num - 1) and shuffle it.
Last repeat block takes the objects from the object variable in a random order (according to listNum) and move them forward.

If you have any questions, feel free to ask

1 Like

Whew…thank you so much! And thanks also for the offer of further support. That’s very kind

I have tried to replicate your example a couple of times.The result was always:
Cospace%20Edu%204

The name of the persons wasn’t said and the numbers were always in the same order

My code (as I said I tried it several times) was…

1 Like

Your second repeat block is not working. Because in conditions statement you set initial value to

Questions - 1

instead of

num -1

and that loop was not executed

doh Thank you very much. I have looked several times over it but sometimes it seems you are struck with blindness :pensive::relieved: Thank you again!

Edit: Works like a charm now. Jipiiii

1 Like

Something really weird happened. I wanted to take the items in 5 second intervals from the list. When I used the greyed out timer, all worked. When I used the active timer with the loop this happens:
Let’s assume a random list with 5,3,2,1,0 got generated
The man says the first item in the list, in this case 0. Then nothing. When I use the greyed out timer, the man says every second the following item taken from the list. Is this bug?

The problem is, I need an interruptable timer because when a student clicks on the correct answer within the given time, the timer needs to reset and the student should get a score

Can you please share your space, so I can take a look?

This is the tutorial how to do it

Hi.

If you replace block “setze Tezt von” with “Outdoor senior man sage timer” everything would work