Google Classroom
GeoGebraGeoGebra Klaslokaal

recalculating random numbers with a (one-line) script

Introduction

In following applet a function f is defined by two random generated parameters. Additionally the function value of a random generated value is calculated. Clicking on a button racalculates all random numbers in a one-line script.

How do you do this?

  • random parameters: Define: - a = RandomDiscrete({-3, -2, -1, 0, 1, 2, 3}, {5, 5, 3, 1, 3, 5, 5}) to define the parameter a. The command RandomDiscrete() allows you to give each of the possible values a weight to differentiate the probabilities of them. Here 0 is allowed but its probability is reduced. - b = RandomBetween(-3, 3). Each number in the range has an equal probability. - c = RandomBetween(-20, 20).
  • function: Define: f = Polynomial ( a x + b) to create the fuction f. The command Polynomial() prevents the equation to be shown as e.g. f(x) = 1 x + 2.
  • texts: Create: - a dynamic text to show the equation of f. Select f in the list of objects. - a dynamic text to show the function value f(c). Select c in the list of available objects.
  • button: Create a button to recalculate the random values used in the applet. You can recalculate all random generated numbers by insering the definition of them in the command SetValue(), e.g. SetValue(c, RandomBetween(-20,20)). You might as well can recalculate all random generated values in the applet with one scripting command. Just type the command UpdateConstruction() in the script of the button and all will be done.