<s> """<STR_LIT>""" <EOL> import foresight . glibc . random <EOL> import foresight . msvc . rand <EOL> from foresight import lcg <EOL> from math import log , ceil <EOL> def _platform_tmax ( platform ) : <EOL> if platform == "<STR_LIT>" : <EOL> return <NUM_LIT:1> << <NUM_LIT:15> <EOL> elif platform == "<STR_LIT>" : <EOL> return <NUM_LIT> <EOL> def predict_state ( values , platform , value_range = None ) : <EOL> if value_range is None : <EOL> if platform == "<STR_LIT>" : <EOL> return foresight . msvc . rand . predict_state ( values ) <EOL> elif platform == "<STR_LIT>" : <EOL> return foresight . glibc . random . predict_state ( values ) <EOL> else : <EOL> tmax = _platform_tmax ( platform ) <EOL> min = value_range [ <NUM_LIT:0> ] <EOL> max = value_range [ <NUM_LIT:1> ] <EOL> init = int ( ( values [ <NUM_LIT:0> ] - min ) * ( tmax + <NUM_LIT:1.0> ) / ( max - min + <NUM_LIT:1.0> ) ) <EOL> operation = lambda x : rand_range ( x , min , max , tmax ) <EOL> if platform == "<STR_LIT>" : <EOL> for i in range ( <NUM_LIT:2> ** ceil ( <NUM_LIT:16> - log ( max - min , <NUM_LIT:2> ) ) ) : <EOL> for lower in range ( <NUM_LIT:2> ** <NUM_LIT:16> ) : <EOL> num = ( init << <NUM_LIT:16> ) | lower <EOL> state = lcg . verify_candidate ( num , values [ <NUM_LIT:1> : ] , a = <NUM_LIT> , <EOL> c = <NUM_LIT> , m = <NUM_LIT:2> ** <NUM_LIT> , <EOL> masked_bits = <NUM_LIT:16> , <EOL> operation = operation ) <EOL> if state is not None : <EOL> return state <EOL> init += <NUM_LIT:1> <EOL> elif platform == "<STR_LIT>" : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> def rand_range ( n , min , max , tmax ) : <EOL> '''<STR_LIT>''' <EOL> return int ( min + ( max - min + <NUM_LIT:1.0> ) * n // ( tmax + <NUM_LIT:1.0> ) ) <EOL> def from_outputs ( prev_values , platform , value_range = None ) : <EOL> state = predict_state ( prev_values , platform , value_range ) <EOL> tmax = _platform_tmax ( platform ) <EOL> if platform == "<STR_LIT>" : <EOL> gen = foresight . msvc . rand . generate_values ( state ) <EOL> elif platform == "<STR_LIT>" : <EOL> gen = foresight . glibc . random . generate_values ( state ) <EOL> if value_range is None : <EOL> value_range = [ <NUM_LIT:0> , tmax ] <EOL> for prediction in gen : <EOL> yield rand_range ( prediction , value_range [ <NUM_LIT:0> ] , <EOL> value_range [ <NUM_LIT:1> ] , tmax ) <EOL> def from_seed ( seed , platform , value_range = None ) : <EOL> tmax = _platform_tmax ( platform ) <EOL> if platform == "<STR_LIT>" : <EOL> gen = foresight . msvc . rand . from_seed ( seed ) <EOL> elif platform == "<STR_LIT>" : <EOL> gen = foresight . glibc . random . from_seed ( seed ) <EOL> if value_range is None : <EOL> value_range = [ <NUM_LIT:0> , tmax ] <EOL> for prediction in gen : <EOL> yield rand_range ( prediction , value_range [ <NUM_LIT:0> ] , <EOL> value_range [ <NUM_LIT:1> ] , tmax ) </s>
