# Random generator from a list of numbers

**URL:** <https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382>\
**Category:** Questions\
**Created:** [July 9, 2022, 8:24pm UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382 "2022-07-09T20:24:03Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [July 9, 2022, 8:24pm UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/1 "2022-07-09T20:24:03Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [July 9, 2022, 8:58pm UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/2 "2022-07-09T20:58:34Z")

</div>

You can use shuffle on the list and take the first 30 numbers [like this](https://www.desmos.com/calculator/1utsfthsdv).

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

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [July 10, 2022, 2:51am UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/3 "2022-07-10T02:51:48Z")

</div>

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

> **[Check Your Understanding: Unit 1, Lesson 15 (Measures of Center and...](https://teacher.desmos.com/activitybuilder/custom/614cf641fd64c56cd3d95b95)**
>
> by Daniel Wekselgreene

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [July 12, 2022, 9:35pm UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/4 "2022-07-12T21:35:00Z")

</div>

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:

> **[Random Generator from table of values • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/62cb64a6cc52b9e5d24ee31e)**
>
> by Pamela Davis

Thank you

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [July 12, 2022, 11:36pm UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/5 "2022-07-12T23:36:44Z")

</div>

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](https://teacher.desmos.com/activitybuilder/custom/62ce025c39e0e2d024f06cdc) 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.

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [July 13, 2022, 2:28am UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/6 "2022-07-13T02:28:53Z")

</div>

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.

> **[\[Copy of\] \[Copy of\] Random Generator from table of values • Activity Builder...](https://teacher.desmos.com/activitybuilder/custom/62ce22ebb51d4fd1c294dbc2)**
>
> by Pamela Davis

Thank you!!!

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [July 13, 2022, 2:41am UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/7 "2022-07-13T02:41:53Z")

</div>

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).

> **[\[Copy of\] Random Generator from table of values • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/62ce025c39e0e2d024f06cdc)**
>
> by Daniel Wekselgreene

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [July 13, 2022, 2:47am UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/8 "2022-07-13T02:47:49Z")

</div>

This is beautiful! Thank you so much!!

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [August 9, 2022, 12:25am UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/9 "2022-08-09T00:25:46Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [August 9, 2022, 4:15am UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/10 "2022-08-09T04:15:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [August 9, 2022, 3:21pm UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/11 "2022-08-09T15:21:08Z")

</div>

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.

> **[Desmos | Graphing Calculator](https://www.desmos.com/calculator/cjgcadtkxi)**
>
> Explore math with our beautiful, free online graphing calculator. Graph functions, plot points, visualize algebraic equations, add sliders, animate graphs, and more.

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [August 9, 2022, 4:53pm UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/12 "2022-08-09T16:53:30Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Daniel\_Wekselgreene](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_wekselgreene/32/1819_2.png) [@Daniel\_Wekselgreene](https://cl.desmos.com/u/Daniel_Wekselgreene)\
**Post date:** [August 10, 2022, 1:05am UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/13 "2022-08-10T01:05:03Z")

</div>

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

> **[\[Copy of\] Random Generator from table of values • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/62ce025c39e0e2d024f06cdc)**
>
> by Daniel Wekselgreene

---

<div class="post-metadata">

**Author:** ![Pamela\_Davis](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/pamela_davis/32/1890_2.png) [@Pamela\_Davis](https://cl.desmos.com/u/Pamela_Davis)\
**Post date:** [August 11, 2022, 6:13pm UTC](https://cl.desmos.com/t/random-generator-from-a-list-of-numbers/4382/14 "2022-08-11T18:13:28Z")

</div>

That works! Thank you!

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

> **[3.2: Investigation 7 • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/62f15800a75d61eefa058c01?collections=61899ae70714628e61ee47de)**
>
> by Pamela Davis
