{%hackmd 5xqeIJ7VRCGBfLtfMi0_IQ %}
# Properties of a function
## Problem
Run the SageMath code below or simply click [here](https://sagecell.sagemath.org/?q=lnkvik).
```python=
### code
set_random_seed(None) # try a different number
print_ans = False
inj = choice([True, False])
sur = choice([True, False])
S = list(range(1,5))
if inj and sur:
T = list(range(1,5))
if inj and not sur:
T = list(range(1,6))
if not inj and sur:
T = list(range(1,4))
if not inj and not sur:
T = list(range(1,5))
while True:
f = {s: choice(T) for s in S}
ran = list(set(f.values()))
if inj == (len(ran) == len(S)) and sur == (len(ran) == len(T)):
break
print("S =", S)
print("T =", T)
print("f : S --> T")
for s in S:
print("f(%s) ="%s, f[s])
if print_ans:
print("Injective?", inj)
print("Surjective?", sur)
print("range(f) =", ran)
```
Replace `None` with your favorite number and run the code again. The outcome is a function $f$.
Is $f$ injective? Is $f$ surjective? What is $\range(f)$?
*This note can be found at Course website > Learning resources.*