Assuming a GPIO pins outputs 5V, and you need 20 mA (0.02A), why not use a resistor of 250 ohm?
V = I * R <=>
5 = 0.02 * R <=>
R = 5 / 0.02 = 250 ohm
For 4 mA you use a resistor of 5 = 0.004 * R <=> R = 5 / 0.004 = 1,250 ohm
If you want it from the same GPIO pin, you can use also a trick:
- Take a LED from a GPIO which you control by PWM
- Tie a photosensor against the LED and put tape around both the LED and the photosensor
- The photosensor will have a certain resistance (you can control it by the LED)
- Run your circuit needing a current from 4-20mA through that photosensor.