Example #1
0
def get_bytes_bitmap(length, samples):

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

    for _ in range(samples):
        array = rand.bytes(length)
        for byte in array:
            bitmap[byte] += 1

    return bitmap
Example #2
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()
Example #3
0
def test_rand_bytes():

    lengths = [1, 3, 32, 17, 64]

    for length in lengths:
        bitmap = get_bytes_bitmap(length, 1)

        total = 0
        for count in bitmap:
            total += count

        assert(total == length), "rand.bytes() returned unexpected length"

    # similar to shuffled gauss count we can expect a random 256 byte array to include each value about once..
    length=256
    samples = 100
    byte_array = rand.bytes(length)
    _, real = get_gauss_sum(byte_array, samples)

    n = 255
    expect = n/2*(n+1)

    assert(abs(real/samples / expect) < 0.1), "rand.bytes() bias detected, gauss count: %d != %d" % (real/samples,expect)