<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def randomize(self, device=None, percent=100, silent=False):
 """ Writes random data to the beginning of each 4MB block on a block device this is useful when performance testing the backup process (Without any optional arguments will randomize the first 32k of each 4MB block on 100 percent of the device) """

        volume = self.get_volume(device)
        # The number of blocks in the volume
        blocks = int(volume['size'] / BLOCK_SIZE)
        # How many writes should be to the device
        # (based on the percentage requested)
        num_writes = int(blocks * percent * 0.01)
        # Build a list of offsets we write to
        offsets = sorted(random.sample(range(blocks), num_writes))
        total = 0

        if not silent:
            print('Writing urandom to %s bytes in %s' % (volume['size'],
                                                         volume['path']))

        with open(volume['path'], 'w') as file:
            for offset in offsets:
                if not silent:
                    self.dot()
                file.seek(offset * BLOCK_SIZE)
                # Create a random string 32k long then duplicate
                # the randomized string 128 times (32768 * 128 = 4MB)
                data = os.urandom(32768) * 128
                total += len(data)
                # write out the 4MB block of randomized data
                file.write(data)
        print("\nWrote: %s" % total)