If you want the function to be smooth then one which approximates the shape you drew is a sigmoid:

This function has a range of (0,1) but is not constant anywhere (though you can tighten up the function to make the derivative very small as x goes away from 0)

You can also define such a function peicewise if you want the function to be constant on some intervals.