Random generator from a list of numbers

I have a table of 200 numbers. The numbers have repeats and are not consecutive. I would like to randomly choose 30 of the numbers. I know there has to be a way to do this, but I can’t figure it out and I haven’t been able to find a thread with it.

Also, after the random list is generated, my students will need to compute the mean. Can I code so that it will give me a check on the teacher screen?

Thank you!

1 Like

You can use shuffle on the list and take the first 30 numbers like this.

I believe if you use something like random(L,30), it takes 30 random elements from L with replacement.

You might also want to look at screens 8 and 9 here. Having students calculate mean from a randomized set.

1 Like

I think my original post was confusing. I have found code that I have borrowed and modified that will generate the 30 random values from my list of values. However, I would like to modify, if possible, so that the 30 random values are summarized into a table or other list to make it easier to work with and, also, I would student answer for the mean to be checked and show correct/incorrect on the teacher dashboard.

Here’s a portion of my activity:

Thank you

If you are open to showing the numbers in a graph, I think it’s easier than in a table. Here is an example: [Copy of] Random Generator from table of values • Activity Builder by Desmos Correctness should work - you can set the tolerance in the graph to determine how close the answer needs to be in order to be marked correct.

Thank you! This is so much easier! However, there are a few things that I still need help with. This line: P=[(x,y) for x =[1…5],y=[1…5]]{s_{how}=} results in a 5x5 view for the students. I changed a 5 for a 6 and it now shows 30 random values but the 6th row or 6th column is out of view. I keep trying to change the view window and I can’t get it to show. Not sure what I am doing wrong here.

Also, I would like them to only be able to press the randomize button once. How can I disable the button after the first press?

I didn’t check this, but this will choose 30 values without replacement? Correct?

Here’s my update with my list of values put in.

Thank you!!!

Oh yeah, my bad. I used the bounds sink in the CL for the graph, which overwrites whatever you set within the graph itself. I just updated that.

I also made the button disable after 1 press.

Yes, this should be 30 without replacement - I just used the code you already had in the graph. Since you are creating a list of 1 - 200, then shuffling it and taking the first 30, they will all be different.

I also changed the graph to a sketch so students can cross off numbers they used (you can easily change it back if you like).

This is beautiful! Thank you so much!!

1 Like

Hi, Daniel.

I used this code to randomly choose x number of values and it works fabulously! Now, I am wondering if there is a way to randomly choose from the first 5 values and then choose every 5th value from that starting place?

Thank you for your assistance!

Hi Pamela,

I’m sure it can be done, but I’m having trouble understanding exactly what you are asking for. Can you give me a specific example of how this might look?

Dan

How’s this? L_new follows your logic, but I’m not sure why you want the initial to be random from the first five. I think L_alt achieves the same thing but simpler.

I have a specific list of 236 values. I want students to find the mean of every 5th value but I don’t want (a) them taking the time to “locate” those values and (b) I don’t want all of the students with the same list of values. My idea is they can start at the 1st value and then get the 6th, the 11th, etc; or start at 2nd and then get the 7th, 12th, etc; or start at the 3rd with the 8th, 12th, etc and so forth. Ultimately there would by 5 different lists that would return. I just don’t want to set up 5 different lists of values. I am hoping the graph component can do it for me with the list I have. Hopefully this makes sense.

Thank you!

Check out screen 2 here. Is this what you are looking for?

That works! Thank you!

In case anyone is looking for the complete activity, here it is:

1 Like