Fix errors in totem.nn.checkTypeCastable with stochastic output

The random number generator is returned to the original state before
running the module in the cast state.