#!/usr/bin/env python3 class Expr: def __init__(self,s): self.s=s def convert_to_Expr_if_int(self, n): if isinstance(n, int): return Expr(str(n)) if isinstance(n, Expr): return n raise AssertionError # unsupported type def __str__(self): return self.s def __xor__(self, other): return Expr("(" + self.s + "^" + self.convert_to_Expr_if_int(other).s + ")") def __mul__(self, other): return Expr("(" + self.s + "*" + self.convert_to_Expr_if_int(other).s + ")") def __add__(self, other): return Expr("(" + self.s + "+" + self.convert_to_Expr_if_int(other).s + ")") def __and__(self, other): return Expr("(" + self.s + "&" + self.convert_to_Expr_if_int(other).s + ")") def __rshift__(self, other): return Expr("(" + self.s + ">>" + self.convert_to_Expr_if_int(other).s + ")") seed=Expr("initial_seed") def rand(): global seed seed=seed*1103515245+12345 return (seed>>16) & 0x7fff for i in range(10): print (i, ":", rand())