Exemple #1
0
def test_coin_semantics():

    samples = 1000

    check = 0
    for _ in range(samples):
        if rand.int(2) == 0: # chance 1 out of 2
            check += 1
    real = check/samples

    assert(abs(check/samples - 1/2) < 0.1), "Coin toss bias - semantics mismatch?"

    check = 0
    for _ in range(samples):
        if rand.int(4) == 0: # chance 1 out of 4
            check += 1
    
    assert(abs(check/samples - 1/4) < 0.1), "Coin toss bias - semantics mismatch?"

    check = 0
    for _ in range(samples):
        if rand.int(100) < 20: # 20%
            check += 1

    assert(abs(check/samples - 0.2) < 0.1), "Coin toss bias - semantics mismatch?"

    check = 0
    for _ in range(samples):
        if rand.int(2) == 0:
            if rand.int(4) == 0:
                pass
            else:
                check += 1 # 3/4 * 1/2

    assert(abs(check/samples - 3/4*1/2) < 0.1), "Coin toss bias - semantics mismatch?"
Exemple #2
0
    def should_be_scheduled(self, queue, node):
        SKIP_CRASHING_PROB = 80
        SKIP_NONFAV_PROB = 50

        if node.get_exit_reason() != "regular":
            if rand.int(100) < SKIP_CRASHING_PROB:
                return False

        if node.get_state() == "final":
            if not node.get_favorite() and rand.int(100) < SKIP_NONFAV_PROB:
                return False
        return True
Exemple #3
0
 def __check_colorization(self, orig_hash, payload_array, min, max):
     backup = payload_array[min:max]
     for i in range(min, max):
         payload_array[i] = rand.int(255)
     new_hash = self.__get_bitmap_hash(payload_array)
     if new_hash is not None and new_hash == orig_hash:
         return True
     else:
         payload_array[min:max] = backup
         return False
Exemple #4
0
def get_int_bitmap(limit, samples):

    elements = limit
    bitmap = [0 for _ in range(elements)]

    for _ in range(samples*elements):
        val = rand.int(limit)
        bitmap[val] += 1

    return bitmap
Exemple #5
0
def random_generalized(grimoire_inference):
    rand_generalized = list(
        grimoire_inference.generalized_inputs.keys())[rand.int(
            len(grimoire_inference.generalized_inputs))]
    rand_generalized = pad_generalized_input(rand_generalized)

    if rand.int(100) > CHOOSE_SUBINPUT and len(rand_generalized) > 0:
        if rand.int(100) < 50 and len(rand_generalized) > 0:
            gap_indices = filter_gap_indices(rand_generalized)
            min_index, max_index = rand.select(gap_indices), rand.select(
                gap_indices)
            min_index, max_index = min(min_index,
                                       max_index), max(min_index, max_index)
            rand_generalized = rand_generalized[min_index:max_index + 1]
        else:
            random_token = list(grimoire_inference.tokens.keys())[rand.int(
                len(grimoire_inference.tokens))]
            rand_generalized = pad_generalized_input(random_token)

        assert rand_generalized[0] == b'' and rand_generalized[-1] == b''
    return rand_generalized
Exemple #6
0
    def handle_busy(self):
        busy_timeout = 1
        kickstart = False

        if kickstart: # spend busy cycle by feeding random strings?
            log_slave("No ready work items, attempting random..", self.slave_id)
            start_time = time.time()
            while (time.time() - start_time) < busy_timeout:
                meta_data = {"state": {"name": "import"}, "id": 0}
                payload = rand.bytes(rand.int(32))
                self.logic.process_node(payload, meta_data)
        else:
            log_slave("No ready work items, waiting...", self.slave_id)
            time.sleep(busy_timeout)
        self.conn.send_ready()