# Randomizer, Numbers, Integers, & Lists in CL and Graphs

**URL:** <https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406>\
**Category:** Questions\
**Created:** [February 26, 2019, 4:46pm UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406 "2019-02-26T16:46:11Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ASmith](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/asmith/32/360_2.png) [@ASmith](https://cl.desmos.com/u/ASmith)\
**Post date:** [February 26, 2019, 4:46pm UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/1 "2019-02-26T16:46:11Z")

</div>

I’ve got a list of numbers in the Graph.  
I’m trying to randomly pull a number from the list.  
My goal is to be able to adjust the list A\_L. Therefore, I’ve created A\_C to count the length of the list. So A\_C is always an integer. A\_P is randomly choosing a position in the list and then I end up with the value A\_V that I’ll actually use for the process.  
A\_C works correctly on finding the length, but the random piece is returning NaN.

I’m wondering if my errors are caused because CL needs to know (force) the fact that A\_C is always an integer?  
Graph CL area:  
 ![random1](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/1X/79c08f9d05cefe4694d3e5e20be561daf4508ea0.png)  
Graph:

 ![random2](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/1X/ac3fa6f6e193a418fb2fffb175197622f7f68cf7.png)

A better explanation of what I’m doing:

1. A\_L is a list of numbers in the graph
2. A\_C is the count of the length of the list A\_L
3. A\_P is a random integer in the CL that grabs a “position number” from 1 through A\_C.
4. A\_V is assigned a value by using the “position number” A\_P to select a number from list A\_L.

NOTE: I know this worked when I used number(“a”):r.int(1,20). So the issue seems to be based upon how I’m trying to call the variables with subscripts in CL.

---

<div class="post-metadata">

**Author:** ![JayChow](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/jaychow/32/1674_2.png) [@JayChow](https://cl.desmos.com/u/JayChow)\
**Post date:** [February 26, 2019, 5:38pm UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/2 "2019-02-26T17:38:55Z")

</div>

I _think_ you can only put numbers (not sources or variables) into the bounds for the random generator.

In any case, here’s an example that might work for you. The probabilities might not be perfect but they’re pretty good. The max is built into the expression to make the index 1 when r=0 (the probability of which is very small, like 10^-15 small or something). Other than making r=0 index 1, the probabilities should hold.

graph script:  
`r = randomGenerator()`  
`number("r"): r.float(0.00000000000001,1)`

[https://www.desmos.com/calculator/uefn7ij9e5](https://www.desmos.com/calculator/uefn7ij9e5)

---

<div class="post-metadata">

**Author:** ![ASmith](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/asmith/32/360_2.png) [@ASmith](https://cl.desmos.com/u/ASmith)\
**Post date:** [February 26, 2019, 6:23pm UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/3 "2019-02-26T18:23:00Z")

</div>

Thanks!  
Not being able to put variables in the random generator would explain why I get the error.  
(But just to check my CL code understanding, if the variable was allowable there, I had it right?)  
(This code is being used in an extension of your equation solver activity.)

---

<div class="post-metadata">

**Author:** ![eric](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/eric/32/10_2.png) [@eric](https://cl.desmos.com/u/eric)\
**Post date:** [February 26, 2019, 7:10pm UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/4 "2019-02-26T19:10:29Z")

</div>

I think this is expected to work the way that you wrote it.

Here’s an example: [Random with variable bounds • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/5c758d9217833053b996e711)

I might try showing the minimum and maximum bounds, and the random seed in a note, to make sure they’re what you think they should be.

---

<div class="post-metadata">

**Author:** ![ASmith](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/asmith/32/360_2.png) [@ASmith](https://cl.desmos.com/u/ASmith)\
**Post date:** [February 26, 2019, 7:31pm UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/5 "2019-02-26T19:31:32Z")

</div>

Eric: Oh! Good to know!  
Jay: Your new coding that you recommended (along with the graph stuff) doesn’t redo the randomizer when I press the button. Oops, had to add the submit count back into the random generator.

After looking at Eric & Jay’s suggestions & links, I think my error was that in an earlier rendition, I included a slider for a value that now no longer likes having the slider. I guess when you create a slider for a number variable, that’s fine CL overwrites it. But if the slider is tied to a value in a list, then no can do…complaint (it tells me I defined it too many times).  
Seems to be working now as intended.

So here’s the latest rendition. Using Jay’s randomizer inside the graph, although my original (with the fix about sliders) and Eric’s methods work also!  
The red points were to test the values and can be deleted.

> **[\[AMS\_CL\_edit2\] Equation Solution Counter • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/5c7554ba8af4f37d60aac89b)**
>
> For this version, my goal is to create the variables that will control the symbol for the equation/inequality.
> Also, to clean up the other variables so they are more consistent.
> 
> Note is created in pieces using variables.
> Then the final statement is...

Our next hope is to randomize a symbol for the equation/inequality: \<, \<=, =, \>=, \>

---

<div class="post-metadata">

**Author:** ![HumanizedMath](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/humanizedmath/32/2947_2.png) [@HumanizedMath](https://cl.desmos.com/u/HumanizedMath)\
**Post date:** [March 18, 2019, 2:06am UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/6 "2019-03-18T02:06:19Z")

</div>

You can randomize symbols or pictures (whatever you want) by using a restricted domain. Say your random variable is “Q” and Q controls the inequality symbol which is at the point (0,1). Q is a random value from 1 to 5  
1 =  
2 \<  
3 \<=  
4 \>  
5 \>=

Then write five corresponding points where one of the coordinates has a restricted domain

({Q=1:0},1) check label =  
({Q=2:0},1) check label \<  
({Q=3:0},1) check label \<=  
({Q=4:0},1) check label \>  
({Q=5:0},1) check label \>=

Here is a cracked out version I made a few months back.

> **[Random Card Deck • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/5c0c0660dbdefd757cc8f645)**
>
> by Vince Panetta

---

<div class="post-metadata">

**Author:** ![Jeewant\_Kaushal](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/jeewant_kaushal/32/1184_2.png) [@Jeewant\_Kaushal](https://cl.desmos.com/u/Jeewant_Kaushal)\
**Post date:** [December 15, 2020, 2:39am UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/7 "2020-12-15T02:39:08Z")

</div>

Hey @HumanizedMath. Your random gen is amazing. I was wondering if there would be a way to make it generate just either 2 or 3 cards at the most. I was looking from all the CL and I def couldn’t figure it out. The more i tried to edit the CL, the more I kept getting confused.

PS. Still very new to doing all the CL

---

<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:** [December 15, 2020, 6:06am UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/8 "2020-12-15T06:06:07Z")

</div>

There are some newer list functions that might help. You could have a list 1-52 to designate which cards. There is a shuffle function. You can use brackets after the name of a list to designate which items to select form it.

```auto
D=shuffle[1...52] #a shuffled deck
C=D[1...3] #take the first three elements (cards) of list D
D_1=D[4...52] #the remaining deck

```

I think a lot of these functions weren’t available when @HumanizedMath did his impressive coding.

---

<div class="post-metadata">

**Author:** ![HumanizedMath](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/humanizedmath/32/2947_2.png) [@HumanizedMath](https://cl.desmos.com/u/HumanizedMath)\
**Post date:** [December 16, 2020, 2:17pm UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/9 "2020-12-16T14:17:53Z")

</div>

I wouldn’t worry about the CL too much on this one. It was a long build in order to get the cards not to repeat. It essentially draws a number 1-52 then draws a number from the remaining etc.

So if you want to use just two cards we would make the other 3 random values a number outside of 1-52 (let’s say 53)

If you wanted to get cute you could make some new parameter that you set 1 to 5 and have r\_1, r\_2, etc. be if then statements… eh hell. I will adjust it real quick

 ![image](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/3/30d7b973f0d348d6c19e805f6df2942ebbd6ec41.png) `

---

<div class="post-metadata">

**Author:** ![HumanizedMath](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/humanizedmath/32/2947_2.png) [@HumanizedMath](https://cl.desmos.com/u/HumanizedMath)\
**Post date:** [December 16, 2020, 2:29pm UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/10 "2020-12-16T14:29:00Z")

</div>

I think my use of mod made it so 53 doesn’t work as the generator itself, so I used sqrt(-1)

It’s updated now. The old link should reflect it. There’s a variable at the top that denotes the number of cards now.

---

<div class="post-metadata">

**Author:** ![Jeewant\_Kaushal](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/jeewant_kaushal/32/1184_2.png) [@Jeewant\_Kaushal](https://cl.desmos.com/u/Jeewant_Kaushal)\
**Post date:** [January 5, 2021, 9:41pm UTC](https://cl.desmos.com/t/randomizer-numbers-integers-lists-in-cl-and-graphs/406/11 "2021-01-05T21:41:13Z")

</div>

Sorry for replying late. Just getting back into the the groove of things from the holidays.

Thanks you so much for your help on this! Amazing stuff!
