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

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:

Graph:

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.

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

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

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

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.

2 Likes

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.

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

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.

1 Like

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

1 Like

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.

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

1 Like

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

`

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.

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!