How to provide students with a mystery function in Python

Viewed 261

I'm teaching a discrete math course in which I've incorporated a programming component. We have been using Python Notebooks through Jupyter.

We're coming up on a section in probability theory, and I would like to provide them with a "mystery random variable:" I want students to be able to sample the random variable without knowing how it is defined.

I don't know the best way to implement this, and was hoping someone could provide a suggestion. Here are the features that I want:

  • I define one or several random variables (preferably in Python),
  • The students should be able to sample from the random variable in a Python notebook (so they can do experimentation with it), but
  • the students should not be able to see the code that defines the random variable.
1 Answers

If this system support modules, you could define a function returning several random values (for instance giving an index) or several functions returning each a random value and put these functions in one module that your students don't have access to. They could import the .pyc module and use it but not seen the codes inside it.

Related