コード例 #1
0
    def rstr(self,
             alphabet,
             start_range=None,
             end_range=None,
             include='',
             exclude=''):
        """Generate a random string containing elements from 'alphabet'

        By default, rstr() will return a string between 1 and 10 characters.
        You can specify a second argument to get an exact length of string.

        If you want a string in a range of lengths, specify the start and end of
        that range as the second and third arguments.

        If you want to make certain that particular characters appear in the
        generated string, specify them as "include".

        If you want to *prevent* certain characters from appearing, pass them as
        'exclude'.

        """
        popul = [char for char in list(alphabet) if char not in list(exclude)]

        if end_range is None:
            if start_range is None:
                start_range, end_range = (1, 10)
            else:
                k = start_range

        if end_range:
            k = randint(start_range, end_range)

        result = sample_wr(popul, k) + list(include)
        random_shuffle(result)
        return ''.join(result)
コード例 #2
0
ファイル: rstr_base.py プロジェクト: Acidburn0zzz/GLBackend
    def rstr(self, alphabet, start_range=None,
             end_range=None, include='', exclude=''):
        """Generate a random string containing elements from 'alphabet'

        By default, rstr() will return a string between 1 and 10 characters.
        You can specify a second argument to get an exact length of string.

        If you want a string in a range of lengths, specify the start and end of
        that range as the second and third arguments.

        If you want to make certain that particular characters appear in the
        generated string, specify them as "include".

        If you want to *prevent* certain characters from appearing, pass them as
        'exclude'.

        """
        popul = [char for char in list(alphabet) if char not in list(exclude)]

        if end_range is None:
            if start_range is None:
                start_range, end_range = (1, 10)
            else:
                k = start_range

        if end_range:
            k = randint(start_range, end_range)

        result = sample_wr(popul, k) + list(include)
        random_shuffle(result)
        return ''.join(result)
コード例 #3
0
 def test_009_random_shuffle(self):
     ordered = [0, 1, 2, 3, 4, 5]
     shuffle = utility.random_shuffle(ordered)
     self.assertEqual(len(ordered), len(shuffle))
     for i in ordered:
         self.assertTrue(i in shuffle)
コード例 #4
0
 def test_009_random_shuffle(self):
     ordered = [0, 1, 2, 3, 4, 5]
     shuffle = utility.random_shuffle(ordered)
     self.assertEqual(len(ordered), len(shuffle))
     for i in ordered:
         self.assertTrue(i in shuffle)