source("http://macosa.dima.unige.it/r.R")    # If I have not already loaded the library
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
S 21 Random generator of exercises

# See here for "runif" and "set.seed".

# An example of how to use runif to randomly generate exercises

x=floor(runif(2,min=1,max=10)); cat(x[1]," x ",x[2], " = ?", "\n")
#4  x  7  = ?
x=floor(runif(2,min=1,max=10)); cat(x[1]," x ",x[2], " = ?", "\n")
#3  x  2  = ?

# I cannot foresee the output

# But if I use seet.seed with a given integer input, I can fix the order of generating
# the numbers

set.seed(2145); x=floor(runif(2,min=1,max=10)); cat(x[1]," x ",x[2], " = ?", "\n")
#7  x  5  = ?
set.seed(2145); x=floor(runif(2,min=1,max=10)); cat(x[1]," x ",x[2], " = ?", "\n")
#7  x  5  = ?
# ...

# Another example:

x <- 3+runif(1)*5+runif(10000)^(runif(1)+0.7)*(runif(1)+5)
BF=4; HF=1.5; statistic(x)
x <- 3+runif(1)*5+runif(10000)^(runif(1)+0.7)*(runif(1)+5)
BF=4; HF=1.5; statistic(x)

   

# If I use set.seed:

set.seed(153); x <- 3+runif(1)*5+runif(10000)^(runif(1)+0.7)*(runif(1)+5)
BF=4; HF=1.5; statistic(x)
set.seed(153); x <- 3+runif(1)*5+runif(10000)^(runif(1)+0.7)*(runif(1)+5)
BF=4; HF=1.5; statistic(x)            # the same exercise, specified by the "seed" 153

   
#
# This trick can be use by a person to practice and check the answers.
# It can be use by a teacher. He can prepare class-tests by putting at the beginning
# set.seed(N) with N different for the various pupils (and jotting down the various N).

Other examples of use