Python random.next() Examples

The following are code examples for showing how to use random.next(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 6 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        other_data_size = buf_size + self.server_info.overhead
        # ????random???????????????????????????????
        random.init_from_bin_len(last_hash, buf_size)
        # final_pos ?????pos~(data_size_list0.len-1)??
        # ??data_size_list0?????????????????buf
        if other_data_size >= self.data_size_list0[-1]:
            if other_data_size >= 1440:
                return 0
            if other_data_size > 1300:
                return random.next() % 31
            if other_data_size > 900:
                return random.next() % 127
            if other_data_size > 400:
                return random.next() % 521
            return random.next() % 1021

        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        # random select a size in the leftover data_size_list0
        final_pos = pos + random.next() % (len(self.data_size_list0) - pos)
        return self.data_size_list0[final_pos] - other_data_size 
Example 2
Project: shadowsocksr-python   Author: nanqinlang-shadowsocksr   File: auth_chain.py    (license) View Source Project 6 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size >= 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list))
        if final_pos < len(self.data_size_list):
            return self.data_size_list[final_pos] - buf_size - self.server_info.overhead

        pos = bisect.bisect_left(self.data_size_list2, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list2))
        if final_pos < len(self.data_size_list2):
            return self.data_size_list2[final_pos] - buf_size - self.server_info.overhead
        if final_pos < pos + len(self.data_size_list2) - 1:
            return 0

        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 3
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 6 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        other_data_size = buf_size + self.server_info.overhead
        # ????random???????????????????????????????
        random.init_from_bin_len(last_hash, buf_size)
        # final_pos ?????pos~(data_size_list0.len-1)??
        # ??data_size_list0?????????????????buf
        if other_data_size >= self.data_size_list0[-1]:
            if other_data_size >= 1440:
                return 0
            if other_data_size > 1300:
                return random.next() % 31
            if other_data_size > 900:
                return random.next() % 127
            if other_data_size > 400:
                return random.next() % 521
            return random.next() % 1021

        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        # random select a size in the leftover data_size_list0
        final_pos = pos + random.next() % (len(self.data_size_list0) - pos)
        return self.data_size_list0[final_pos] - other_data_size 
Example 4
Project: ShadowSocksShare-OpenShift   Author: the0demiurge   File: auth_chain.py    (license) View Source Project 6 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size >= 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list))
        if final_pos < len(self.data_size_list):
            return self.data_size_list[final_pos] - buf_size - self.server_info.overhead

        pos = bisect.bisect_left(self.data_size_list2, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list2))
        if final_pos < len(self.data_size_list2):
            return self.data_size_list2[final_pos] - buf_size - self.server_info.overhead
        if final_pos < pos + len(self.data_size_list2) - 1:
            return 0

        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 5
Project: shadowsocksR-b   Author: hao35954514   File: auth_chain.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def next(self):
        x = self.v0
        y = self.v1
        self.v0 = y
        x ^= ((x & xorshift128plus.mov_mask) << 23)
        x ^= (y ^ (x >> 17) ^ (y >> 26)) & xorshift128plus.max_int
        self.v1 = x
        return (x + y) & xorshift128plus.max_int 
Example 6
Project: shadowsocksR-b   Author: hao35954514   File: auth_chain.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def init_from_bin_len(self, bin, length):
        bin += b'\0' * 16
        bin = struct.pack('<H', length) + bin[2:]
        self.v0 = struct.unpack('<Q', bin[:8])[0]
        self.v1 = struct.unpack('<Q', bin[8:16])[0]

        for i in range(4):
            self.next() 
Example 7
Project: shadowsocksR-b   Author: hao35954514   File: auth_chain.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size > 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 8
Project: shadowsocksR-b   Author: hao35954514   File: auth_chain.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def udp_rnd_data_len(self, last_hash, random):
        random.init_from_bin(last_hash)
        return random.next() % 127 
Example 9
Project: shadowsocksR-b   Author: hao35954514   File: auth_chain.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def rnd_start_pos(self, rand_len, random):
        if rand_len > 0:
            return random.next() % 8589934609 % rand_len
        return 0 
Example 10
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def next(self):
        x = self.v0
        y = self.v1
        self.v0 = y
        x ^= ((x & xorshift128plus.mov_mask) << 23)
        x ^= (y ^ (x >> 17) ^ (y >> 26)) & xorshift128plus.max_int
        self.v1 = x
        return (x + y) & xorshift128plus.max_int 
Example 11
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_from_bin_len(self, bin, length):
        bin += b'\0' * 16
        bin = struct.pack('<H', length) + bin[2:]
        self.v0 = struct.unpack('<Q', bin[:8])[0]
        self.v1 = struct.unpack('<Q', bin[8:16])[0]

        for i in range(4):
            self.next() 
Example 12
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size > 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 13
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def udp_rnd_data_len(self, last_hash, random):
        random.init_from_bin(last_hash)
        return random.next() % 127 
Example 14
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_start_pos(self, rand_len, random):
        if rand_len > 0:
            return random.next() % 8589934609 % rand_len
        return 0 
Example 15
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size >= 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list))
        # ??random??????????????????if false
        if final_pos < len(self.data_size_list):
            return self.data_size_list[final_pos] - buf_size - self.server_info.overhead

        # ??if false???2?????????????????
        pos = bisect.bisect_left(self.data_size_list2, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list2))
        if final_pos < len(self.data_size_list2):
            return self.data_size_list2[final_pos] - buf_size - self.server_info.overhead
        # final_pos ?????pos~(data_size_list2.len-1)??
        if final_pos < pos + len(self.data_size_list2) - 1:
            return 0
        # ?1/len(self.data_size_list2)?????????if  ?
        # ?????????????????????  ?
        # assert False

        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 16
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_data_size(self, key):
        if self.data_size_list0:
            self.data_size_list0 = []
        random = xorshift128plus()
        random.init_from_bin(key)
        # ??????12~24-1
        list_len = random.next() % (8 + 16) + (4 + 8)
        for i in range(0, list_len):
            self.data_size_list0.append((int)(random.next() % 2340 % 2040 % 1440))
        self.data_size_list0.sort() 
Example 17
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def check_and_patch_data_size(self, random):
        # append new item
        # when the biggest item(first time) or the last append item(other time) are not big enough.
        # but set a limit size (64) to avoid stack overflow.
        if self.data_size_list0[-1] < 1300 and len(self.data_size_list0) < 64:
            self.data_size_list0.append((int)(random.next() % 2340 % 2040 % 1440))
            self.check_and_patch_data_size(random) 
Example 18
Project: ssrr   Author: do21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_data_size(self, key):
        if self.data_size_list0:
            self.data_size_list0 = []
        random = xorshift128plus()
        random.init_from_bin(key)
        # ??????12~24-1
        list_len = random.next() % (8 + 16) + (4 + 8)
        for i in range(0, list_len):
            self.data_size_list0.append((int)(random.next() % 2340 % 2040 % 1440))
        self.data_size_list0.sort()
        old_len = len(self.data_size_list0)
        self.check_and_patch_data_size(random)
        # if check_and_patch_data_size are work, re-sort again.
        if old_len != len(self.data_size_list0):
            self.data_size_list0.sort() 
Example 19
Project: shadowsocksr-python   Author: nanqinlang-shadowsocksr   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def next(self):
        x = self.v0
        y = self.v1
        self.v0 = y
        x ^= ((x & xorshift128plus.mov_mask) << 23)
        x ^= (y ^ (x >> 17) ^ (y >> 26)) & xorshift128plus.max_int
        self.v1 = x
        return (x + y) & xorshift128plus.max_int 
Example 20
Project: shadowsocksr-python   Author: nanqinlang-shadowsocksr   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_from_bin_len(self, bin, length):
        bin += b'\0' * 16
        bin = struct.pack('<H', length) + bin[2:]
        self.v0 = struct.unpack('<Q', bin[:8])[0]
        self.v1 = struct.unpack('<Q', bin[8:16])[0]

        for i in range(4):
            self.next() 
Example 21
Project: shadowsocksr-python   Author: nanqinlang-shadowsocksr   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size > 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 22
Project: shadowsocksr-python   Author: nanqinlang-shadowsocksr   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def udp_rnd_data_len(self, last_hash, random):
        random.init_from_bin(last_hash)
        return random.next() % 127 
Example 23
Project: shadowsocksr-python   Author: nanqinlang-shadowsocksr   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_start_pos(self, rand_len, random):
        if rand_len > 0:
            return random.next() % 8589934609 % rand_len
        return 0 
Example 24
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def next(self):
        x = self.v0
        y = self.v1
        self.v0 = y
        x ^= ((x & xorshift128plus.mov_mask) << 23)
        x ^= (y ^ (x >> 17) ^ (y >> 26)) & xorshift128plus.max_int
        self.v1 = x
        return (x + y) & xorshift128plus.max_int 
Example 25
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_from_bin_len(self, bin, length):
        bin += b'\0' * 16
        bin = struct.pack('<H', length) + bin[2:]
        self.v0 = struct.unpack('<Q', bin[:8])[0]
        self.v1 = struct.unpack('<Q', bin[8:16])[0]

        for i in range(4):
            self.next() 
Example 26
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size > 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 27
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def udp_rnd_data_len(self, last_hash, random):
        random.init_from_bin(last_hash)
        return random.next() % 127 
Example 28
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_start_pos(self, rand_len, random):
        if rand_len > 0:
            return random.next() % 8589934609 % rand_len
        return 0 
Example 29
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size >= 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list))
        # ??random??????????????????if false
        if final_pos < len(self.data_size_list):
            return self.data_size_list[final_pos] - buf_size - self.server_info.overhead

        # ??if false???2?????????????????
        pos = bisect.bisect_left(self.data_size_list2, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list2))
        if final_pos < len(self.data_size_list2):
            return self.data_size_list2[final_pos] - buf_size - self.server_info.overhead
        # final_pos ?????pos~(data_size_list2.len-1)??
        if final_pos < pos + len(self.data_size_list2) - 1:
            return 0
        # ?1/len(self.data_size_list2)?????????if

        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 30
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_data_size(self, key):
        if self.data_size_list0:
            self.data_size_list0 = []
        random = xorshift128plus()
        random.init_from_bin(key)
        # ??????12~24-1
        list_len = random.next() % (8 + 16) + (4 + 8)
        for i in range(0, list_len):
            self.data_size_list0.append((int)(random.next() % 2340 % 2040 % 1440))
        self.data_size_list0.sort() 
Example 31
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def check_and_patch_data_size(self, random):
        # append new item
        # when the biggest item(first time) or the last append item(other time) are not big enough.
        # but set a limit size (64) to avoid stack overflow.
        if self.data_size_list0[-1] < 1300 and len(self.data_size_list0) < 64:
            self.data_size_list0.append((int)(random.next() % 2340 % 2040 % 1440))
            self.check_and_patch_data_size(random) 
Example 32
Project: luci-oso21   Author: oso21   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_data_size(self, key):
        if self.data_size_list0:
            self.data_size_list0 = []
        random = xorshift128plus()
        random.init_from_bin(key)
        # ??????12~24-1
        list_len = random.next() % (8 + 16) + (4 + 8)
        for i in range(0, list_len):
            self.data_size_list0.append((int)(random.next() % 2340 % 2040 % 1440))
        self.data_size_list0.sort()
        old_len = len(self.data_size_list0)
        self.check_and_patch_data_size(random)
        # if check_and_patch_data_size are work, re-sort again.
        if old_len != len(self.data_size_list0):
            self.data_size_list0.sort() 
Example 33
Project: shadowsocksr   Author: emacsenli   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def next(self):
        x = self.v0
        y = self.v1
        self.v0 = y
        x ^= ((x & xorshift128plus.mov_mask) << 23)
        x ^= (y ^ (x >> 17) ^ (y >> 26)) & xorshift128plus.max_int
        self.v1 = x
        return (x + y) & xorshift128plus.max_int 
Example 34
Project: shadowsocksr   Author: emacsenli   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_from_bin_len(self, bin, length):
        bin += b'\0' * 16
        bin = struct.pack('<H', length) + bin[2:]
        self.v0 = struct.unpack('<Q', bin[:8])[0]
        self.v1 = struct.unpack('<Q', bin[8:16])[0]

        for i in range(4):
            self.next() 
Example 35
Project: shadowsocksr   Author: emacsenli   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size > 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 36
Project: shadowsocksr   Author: emacsenli   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def udp_rnd_data_len(self, last_hash, random):
        random.init_from_bin(last_hash)
        return random.next() % 127 
Example 37
Project: shadowsocksr   Author: emacsenli   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_start_pos(self, rand_len, random):
        if rand_len > 0:
            return random.next() % 8589934609 % rand_len
        return 0 
Example 38
Project: shadowsocksrh   Author: hhhizzz   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def next(self):
        x = self.v0
        y = self.v1
        self.v0 = y
        x ^= ((x & xorshift128plus.mov_mask) << 23)
        x ^= (y ^ (x >> 17) ^ (y >> 26)) & xorshift128plus.max_int
        self.v1 = x
        return (x + y) & xorshift128plus.max_int 
Example 39
Project: shadowsocksrh   Author: hhhizzz   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_from_bin_len(self, bin, length):
        bin += b'\0' * 16
        bin = struct.pack('<H', length) + bin[2:]
        self.v0 = struct.unpack('<Q', bin[:8])[0]
        self.v1 = struct.unpack('<Q', bin[8:16])[0]

        for i in range(4):
            self.next() 
Example 40
Project: shadowsocksrh   Author: hhhizzz   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size > 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 41
Project: shadowsocksrh   Author: hhhizzz   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def udp_rnd_data_len(self, last_hash, random):
        random.init_from_bin(last_hash)
        return random.next() % 127 
Example 42
Project: shadowsocksrh   Author: hhhizzz   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_start_pos(self, rand_len, random):
        if rand_len > 0:
            return random.next() % 8589934609 % rand_len
        return 0 
Example 43
Project: ShadowSocksShare-OpenShift   Author: the0demiurge   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def next(self):
        x = self.v0
        y = self.v1
        self.v0 = y
        x ^= ((x & xorshift128plus.mov_mask) << 23)
        x ^= (y ^ (x >> 17) ^ (y >> 26)) & xorshift128plus.max_int
        self.v1 = x
        return (x + y) & xorshift128plus.max_int 
Example 44
Project: ShadowSocksShare-OpenShift   Author: the0demiurge   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def init_from_bin_len(self, bin, length):
        bin += b'\0' * 16
        bin = struct.pack('<H', length) + bin[2:]
        self.v0 = struct.unpack('<Q', bin[:8])[0]
        self.v1 = struct.unpack('<Q', bin[8:16])[0]

        for i in range(4):
            self.next() 
Example 45
Project: ShadowSocksShare-OpenShift   Author: the0demiurge   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size > 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021 
Example 46
Project: ShadowSocksShare-OpenShift   Author: the0demiurge   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def udp_rnd_data_len(self, last_hash, random):
        random.init_from_bin(last_hash)
        return random.next() % 127 
Example 47
Project: ShadowSocksShare-OpenShift   Author: the0demiurge   File: auth_chain.py    (license) View Source Project 5 votes vote down vote up
def rnd_start_pos(self, rand_len, random):
        if rand_len > 0:
            return random.next() % 8589934609 % rand_len
        return 0