Controlled Randomness needed

twingsister shared this question 7 months ago
Answered

I put this

function ggbOnInit() {

ggbApplet.eval("SetSeed(33)");

}

In a ggb containing just one slider and thick "random" for it. Every time I load this simplest ggb

the slider comes up with a different value. I do not like this!


If you have a ggb activity with self grading and use it as a test this is nice and can limit cheating.

Nevertheless it is quite common to survey the SAME activity BEFORE the test. In this case you might want the students to follow your survey having all the same exercise on their device before

starting (a randomized and new) test. This is quite easy to obtain if SetSeed can seed ALL RANDOM GENERATORS in Geogebra. The K.I.S.S. solution being to develop a separate SURVEY activity by adding the above code to an existing randomized anti cheating test activity.


Is there something I am missing or this centralized seeding is missing? I guess it is quite easy to implement and could be incredibly useful.

Cheers.

Franco

Best Answer
photo

Tatsächlich, danke.

Indeed, thank you.

Comments (18)

photo
1

Please say what you are trying to do exactly (with a concrete example)

photo
1

First of, I think

ggbApplet.eval("SetSeed(33)");

will not do anything because it's not a valid command. (GeoGebra just doesn't give an error unfortunately.) It should rather be

ggbApplet.evalCommand("SetSeed(33)");


That said, the change won't solve the problem. As far as I understand, the init script runs after the construction is complete (otherwise it wouldn't have access to the variables), but at this point the slider value is already set, so SetSeed won't have an affect on it.


No idea if there is a way to start GeoGebra with a predefined Seed (which is what you want I guess), but you could also just reset the needed values from the init script (after SetSeed of course) via RandomUniform or RandomBetween or whatever you need.

photo
1

Thanks for your prompt replies! The code was calling the correct function evalCommand but every time you load this ggb the slider

is different. I expect to have always the same value if the seed has to be considered valid for all the randomness going on in GGB.

In my first mail I devised a real-class situation where you might want this. Furthermore, using existing ggb activities, I expect this to work without big modifications to the code. Just that line in the ggbInit function. May be I will have to take a look in the code. Does not sound too difficult to fix.

photo
1

Not sure if you read my comment completely. The "problem" is that the Init script runs too late (after the slider cariable was set randomly). To circumvent this, use the init script to also reset your variable after calling SetSeed, e.g. like this:

ggbApplet.evalCommand("SetSeed(33)");
ggbApplet.evalCommand("a = CopyFreeObject(RandomBetween(-50, 50) / 10)");

photo
photo
1

You have a wrong idea about SetSeed(<number>).

SetSeed() tries (without guarantee) to make the coming random numbers more random. So rather the opposite of what you (probably) want to achieve. Exaggeratedly formulated: SetSeed() does nothing (recognizable).

What you really want to achieve is not clear to me, respectively I can only assume. Maybe you can describe not how but what you want to achieve more precisely, without abbreviations and with an example.

photo
1

SetSeed() tries (without guarantee) to make the coming random numbers more random
Sorry, that's wrong. It makes them deterministic after that

photo
1

i am confused. What is a deterministic random number? Is a deterministic random number reproducible?

photo
1

now I found this in wikipedia

I mean (and write) the result of the algorithm (the random number)

I think you mean: the algorithm is deterministic.

I suspect that the algorithm is and remains deterministic with or without SetSeed() only the determistic algorithm is modified.

Relevant for the questioner remains: SetSeed() does NOT generate a deterministic sequence of random numbers. Probably the questioner should use Shuffle() instead of SetSeed().

photo
1

@rami I think you got this wrong. All (commonly used) random number generators produce deterministic sequences, the only "random" thing is the initial seeding which is based on a current time or some other stuff that has reasonably high external entropy. SetSeed is a way to specify a seed so that you can produce the same pseudo-random sequence over and over which is useful for testing and stuff (and which is what twingsister wants).

photo
1

Tatsächlich, danke.

Indeed, thank you.

photo
1

Thanks rami and artydent for your attention and for your code! This shows is exactly what I meant. SetSeed works for random() as it should be. It goes like that in all programming languages I know. Once seeded the generator give the same sequence if the seed is the same. Please take a look to my (longer) reply below. I had in mind a certain (quite common to me) scenario and I ask to extend the setSeed kingdom to ALL random objects in GGB. I think I can hack the javascript code for this. Can someone point me some docs about the procedure for doing this to have some hope to see the mods integrated in the forthcoming versions?

photo
photo
1

maybe that's what you're looking for.

photo
1

Thanks for your effort! The point is that I am trying to reuse the large amount of wonderful tests out there. They all use random objects but no one offer a "stop randomness" check like in your example. It is unpractical to believe that one can take a look to some ggbs he/she was not the author of and can implement easily this "stop the random" check. My proposal of having a general seed can do the job with one line of code added and this will work, at least for the scenario I put forward in the (longer) answer below.

Thanks anyway

photo
photo
1

Thanks all for your interest. I will take a look at all the ggbs attached. In the meanwhile let me recall the original problem.

This is centered on the following scenario that should be very common.

A teacher is collecting various ggbs from the net. These ggbs implements a self evaluation using Moodle.

That teacher is not the author of these ggbs and have no idea of the code in it.

Since they are used for self evaluation they implement some anti-cheating by using randomized objects (points and numbers) to deliver to each student connected to Moodle a slightly different version of the same exercise.

This thing about Moodle is not so important. In general imagine that a ggb is available for download by students and every time they open it they see a slightly different activity.

I want to have a simple way to control this randomness by SetSeed.

In programming experience a random number generator with a seed gives always the same random sequence when seeded with the same seed.

The point is that in GGB you can define objects to be random (e.g. a slider) and yet there is no way to seed them.

I ask (or I will try to patch the code) to get ALL random objects in GGB seeded by a SetSeed.

In this way a small javascript SetSeed addition in initGgb() can help the teacher to control the class.

If all the students download a copy of some activity (in Moodle or not) and get a different version of the activity

TRAINING FOR THE TEST is going to be a mess. The teacher is going to explain how to cope with the test to a class where every student see a slightly different version of the test.

If all the students download a copy of some activity (in Moodle or not) and get the same version of the activity THE TEST is going to be a cheating session.So during training the ggb must be seeded by the SAME seed for all the students and during the test the seed itsself must be randomized.

I think that making SetSeed a seed for all random objects can help teacher to take somebody else ggb and align the code for this scenario without rewriting all the code.

Actually is rather surprising that this has not been addressed so far.

Can someone please point me some docs about forking in github to develop a patch for it or how to request a feature

and see the development assigned to the asker?


Cheers

Franco

photo
1

Well, I think I have settled this problem. The problem is that some ggb activities (of unknown author and structure) uses

random generation. Therefore if pick a ggb activity from the repo and distribute it to the class, each and every student, upon loading the ggb, gets a different exercise. You might not want this.

To circumvent this situation you can add a RESET button to the activity code (you don't know much about).

Your RESET must simply issue a SetSeed(42) (42 or whatever) followed by pressing F9 or by an UpdateConstruction(). Indeed, after seeding with 42, all the random generators in GGB follow the same pattern. An example is provided.

Load the included ggb and press repeatedly F9. You will get random values. Pressing SET SEED followed by F9 you always get the same sequence of values from various random generators in Geogebra.

So you just have to tell the students to press RESET and F9 e.g. three times and all the class will have the same activity on each device. Nice designed randomness in GGB!

@Artydent thank for your comment! Putting SetSeed in Javascript init gets too late since the construction must already be there. Thinking twice to your insight I imagined that SetSeed followed by UpdateConstruction(). should do the job.

photo
1

The best way to do this is to use the randomSeed parameter if possible https://wiki.geogebra.org/e...

photo
1

Thanks Michael for your suggestion. That's another possibility I wasn't aware of and I agree that Occam razor is always a good approach..

So one can put "randomSeed":33 in HTML to configure the applet (a html sample is included)


<script>  
	var ggbApp = new GGBApplet({"appName":"classic",
                       "randomSeed":33,
                       "useBrowserForJS": false,  
                       "width": 1366,  "height": 768,
			"showToolBar": true, 
                        "showAlgebraInput": true, 
                        "showMenuBar": true, 
                        "borderColor": "#FF0000", 
                        "filename":"translator.ggb" }, true);
    		window.addEventListener("load", function() { 
        	ggbApp.inject('ggb-element');

});</script>

After uploading the applet in the browser you can load the ggb randomslider.ggb into your GGB in the browser and upon loading you will get ALWAYS the slider at 2.4 and that's REALLY GOOD. If you reload the same ggb things change so this might sound confusing. To get all the class with the same exercise students must be told to reload the page in the browser and then reload the ggb. Someone might prefer to click a button in the ggb but this can go in the YMMV category.

A more serious drawback is what happens with the integration with Moodle. Surely some PHP editing can do the job, still I wonder if there is a more Occam-istic and elegant way to tell the Moodle GGB plugin to load the applet applying some parameters. This would be of great help.

Probably the right way to go is some voluntary work from me coding in Php but, before starting, I like to check in this forum if some parameter passing mechanism is already in the Moodle-GGB plugin (or in Moodle in general) and I am simply not aware of.

Cheers

photo
1

Not to waste reader's time I think that an update in the qtype_geogebra plugin is unrealistic. Furthermore on my site I am using mod_geogebra so will seek help there, too. Thanks for attention anyway.


/tWNPulXcLgAAAAAElFTkSuQmCC

photo
© 2021 International GeoGebra Institute