What triggers an update of random numbers?

pirsquared shared this question 7 years ago
Answered

Hi all,


Please see attached worksheet. It is probably not the most efficient way of building this particular worksheet, but it started off basic and I have added to it as I've gone along.


https://ggbm.at/2553329


My problem is that the "mult" variable (which is randomly generated) updates itself on any press of the 'Show' button. Most of the time this then changes the question just as it shows the answers, defeating the purpose. There are quite a few randomly generated numbers in the construction, but they all remain fixed until the UpdateConstruction[] command is run by the 'Next' button - it is only "mult" that updates.


'Show' button script comprises "ShowLayer[2]" and nothing else. "mult" only depends on "gresub(2)", which itself is randomly generated but doesn't update on the 'Show' button. Is there any way I can keep this dependency but stop the update?


Many thanks.

Comments (5)

photo
1

Hi


My problem is that the "mult" variable (which is randomly generated) updates itself on any press of the 'Show' button.


Sorry I can't reproduce this problem.

I use GGB 5.0.199, Desktop, HTML-Chrome, Windows 10


In the attachment

"Bild 1" is before press "show"

"Bild 2" is after press "show"

nothing has changed (also not with a few time)


Raymonde01f81ac9afcefc69f578d81ba50b3d9

31cdbfc3ecf3f6b4721b11ab533e26c8

photo
1

Sorry I can't reproduce this problem.

And now I have gone back into the file, I can't reproduce it myself either! :flushed: Behaves exactly as expected. There must have just been a little glitch that was causing the problem and exiting and reloading appears to have fixed it - I guess I probably should've done this before creating the thread!


Thank you for taking the time to test this, it is appreciated.

photo
2

If you want more control over random numbers then instead of

    UpdateConstruction[]


you can do

    dummy = 0

    a = RandomBetween[0, 10 + 0 * dummy]


then then to generate a new random number just

    SetValue[dummy, 0]

photo
1

In fact it's probably simpler to just do this

    SetValue[a, RandomBetween[0,10]]


if you don't need UpdateConstruction[] to update the random numbers too

photo
1

Thanks, Michael - they seem like sensible approaches for exercising full control over when variables are updated. I shall bear this in mind for future constructions.


Kind regards.

© 2023 International GeoGebra Institute