https://raw.githubusercontent.com/j-towns/ans-notes/master/rans.py. After reading (and understanding) this tutorial, the reader should understand how rANS works, and be able to implement it and prove that it attains a near optimal compression rate.
This paper is intended to be an accessible introduction to the range variant of Asymmetric Numeral Systems (rANS). This version of ANS can be used as a drop in replacement for traditional arithmetic coding (AC). Implementing rANS is more straightforward than AC, and this paper includes pseudo-code which could be converted without too much effort into a working implementation. An example implementation, based on this tutorial, is available at