Created
May 3, 2014 06:12
-
-
Save anonymous/985443b83e60f82161be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import struct | |
def random_padded( blockSize, percent ): | |
result = [] | |
numRandom = percent * blockSize / 100 | |
for x in xrange( numRandom ): | |
result.append( random.randint( 0, 255 ) ) | |
for x in xrange( blockSize - numRandom ): | |
result.append( 0 ) | |
return result | |
def random_reduced( blockSize, percent ): | |
result = [] | |
maxVal = 255 * percent / 100 | |
for x in xrange( blockSize ): | |
result.append( random.randint( 0, maxVal ) ) | |
return result | |
def random_repeated( blockSize, percent ): | |
result = [] | |
if percent == 0: | |
numCopies = blockSize - 1 | |
else: | |
numCopies = 100.0 / percent - 1.0 | |
numCopies += 1 | |
intCopies = int( numCopies ) | |
fracCopies = numCopies - intCopies | |
while len(result) < blockSize: | |
val = random.randint( 0, 255 ) | |
result.append( val ) | |
for x in xrange( intCopies ): | |
result.append( val ) | |
if ( random.uniform( 0.0, 1.0 ) < fracCopies ): | |
result.append( val ) | |
return result[0:blockSize] | |
def writeArrayAsBlock( fileName, block ): | |
f = open( fileName, "wb" ) | |
f.write( bytearray( block ) ) | |
f.close() | |
def main(): | |
for p in [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]: | |
writeArrayAsBlock( "padded-%03d.block" % ( p ), | |
random_padded( 8192, p ) ) | |
writeArrayAsBlock( "reduced-%03d.block" % ( p ), | |
random_reduced( 8192, p ) ) | |
writeArrayAsBlock( "repeated-%03d.block" % ( p ), | |
random_repeated( 8192, p ) ) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment