# Why won't this random generated question desmos count correct answers?

**URL:** <https://cl.desmos.com/t/why-wont-this-random-generated-question-desmos-count-correct-answers/5586>\
**Category:** Questions\
**Created:** [April 8, 2024, 3:23pm UTC](https://cl.desmos.com/t/why-wont-this-random-generated-question-desmos-count-correct-answers/5586 "2024-04-08T15:23:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charles\_Leidecker](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/charles_leidecker/32/5047_2.png) [@Charles\_Leidecker](https://cl.desmos.com/u/Charles_Leidecker)\
**Post date:** [April 8, 2024, 3:23pm UTC](https://cl.desmos.com/t/why-wont-this-random-generated-question-desmos-count-correct-answers/5586/1 "2024-04-08T15:23:56Z")

</div>

I am creating a simple and compound interest practice that generates random numbers for the questions. I would like the count of correct answers to be tallied after each question is answered. Because it is money, I have included code that requires the answer to be rounded to 2 decimal places to be counted correct. Something is not jiving with the way it is counting correct answers though… help please!

I’d also like for the rate to be randomly generated rational decimal numbers with up to 2 decimals instead of positive integers only. Any help on that end would be greatly appreciate as well!

Thanks so much!

[Simple and Compound Interest Practice](https://teacher.desmos.com/activitybuilder/custom/66103ba3f4fb27f8d7a23ac9)

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [April 8, 2024, 6:43pm UTC](https://cl.desmos.com/t/why-wont-this-random-generated-question-desmos-count-correct-answers/5586/2 "2024-04-08T18:43:08Z")

</div>

Everything you’ve put already works, other than you have `roundedAnswer` being dependent on A1.submitted for some reason. So at the point you submit your answer, technically `this.latex` cannot equal `roundedAnswer` because `roundedAnswer` is just “” at that point. If you remove that dependency, it works absolutely fine.

Given that you have a hidden graph component tracking the scores, I would move all of the calculations and random generation stuff into that graph - it’s much easier to do calculations there and then call them using `G1.number('...')`.

To address your final point, if you use `P=round(random()*10,2)` in the graph, this will give you a randomly generated number between 0 and 10 with two decimal places. Then call it in the CL using `G1.number('P')` wherever you need it.

---

<div class="post-metadata">

**Author:** ![Charles\_Leidecker](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/charles_leidecker/32/5047_2.png) [@Charles\_Leidecker](https://cl.desmos.com/u/Charles_Leidecker)\
**Post date:** [April 8, 2024, 7:09pm UTC](https://cl.desmos.com/t/why-wont-this-random-generated-question-desmos-count-correct-answers/5586/3 "2024-04-08T19:09:55Z")

</div>

Thank you very much - removing the dependency did work!

However, the code:

r=round(random()\*10,2) did not work ☹

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [April 8, 2024, 7:12pm UTC](https://cl.desmos.com/t/why-wont-this-random-generated-question-desmos-count-correct-answers/5586/4 "2024-04-08T19:12:12Z")

</div>

Just confirming that you put that expression in the **graph component** , not the CL?  
 ![image](https://canada1.discourse-cdn.com/flex031/uploads/desmos/original/2X/2/2bd9dc44ff32cb4f18551fe8bc670d3f8f6a2cc9.png)

---

<div class="post-metadata">

**Author:** ![Charles\_Leidecker](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/charles_leidecker/32/5047_2.png) [@Charles\_Leidecker](https://cl.desmos.com/u/Charles_Leidecker)\
**Post date:** [April 8, 2024, 7:26pm UTC](https://cl.desmos.com/t/why-wont-this-random-generated-question-desmos-count-correct-answers/5586/5 "2024-04-08T19:26:05Z")

</div>

ahh - no I did not. I’ll try that and get back!

---

<div class="post-metadata">

**Author:** ![Charles\_Leidecker](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/charles_leidecker/32/5047_2.png) [@Charles\_Leidecker](https://cl.desmos.com/u/Charles_Leidecker)\
**Post date:** [April 8, 2024, 7:48pm UTC](https://cl.desmos.com/t/why-wont-this-random-generated-question-desmos-count-correct-answers/5586/6 "2024-04-08T19:48:15Z")

</div>

So doing this does not create a new random number every time the new problem button is pressed?

---

<div class="post-metadata">

**Author:** ![pirsquared](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pirsquared](https://cl.desmos.com/u/pirsquared)\
**Post date:** [April 8, 2024, 11:42pm UTC](https://cl.desmos.com/t/why-wont-this-random-generated-question-desmos-count-correct-answers/5586/7 "2024-04-08T23:42:26Z")

</div>

So that’s because the `random()` hasn’t been seeded.

To get it to update, you would need to replace with `P=round(random(1,s)*10,2)[1]`, and in the CL for the graph include `number('s'): B1.pressCount`

The `random(1,s)` basically means “create a random list of 1 number, using the seed _s_” - hence why we now need to tag [1] onto the end, so that it picks item 1 (from a list of 1).

If that’s too messy for you then you can actually generate a floating point random number in CL using `.float(1,10)` instead of `.int(1,10)`… but you’d have to round it to 2d.p. somehow too.
