Advertisement
Guest User

Brute-Force Example

a guest
Jun 16th, 2016
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import random
  2.  
  3. print '#-------------------------#'
  4. print '| RANDOM NUMBER GENERATOR |'
  5. print '#-------------------------#'
  6. print '\nThis is a Brute-force method. It will test every possible number\nuntil the generated number is found.'
  7. print "\nThis is a viable method as long as the number of attempts isn't outrageous and you have enough hardware resources.\n"
  8. print "In other words, the speed of the program is directly related to the number of attempts and your hardware.\n"
  9. raw_input ("Press ENTER when ready:")
  10. generated_int = random.randint(0,10000) #Change this number to visualize the time differences
  11. guess = 0
  12. while guess <= generated_int:
  13.     print guess
  14.     guess +=1
  15.     if guess == generated_int:
  16.         print 'The generated number is '+str(guess)
  17.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement