Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2014 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/985443b83e60f82161be to your computer and use it in GitHub Desktop.
Save anonymous/985443b83e60f82161be to your computer and use it in GitHub Desktop.
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