How to make sure, Bitcoin private key and bitcoin address generator tools are generating valid key pair? I find lots of tools/scripts written in python which can generate random number then using this random number it generates Bitcoin Private key(WIF) -&gt; Bitcoin Address pair.

I have tried verifying few pairs using www.bitaddress.org >> Wallet Details by entering WIF key and verifying with output address.

But How can one make sure, the tools/scripts will always generate valid address and key pair ?

or is this like this way

if it generates one valid address and key pair it means all the future address and key pairs will be valid ?

i was looking at this https://github.com/shirriff/bitcoin-code

from makeAddr.py

import random, keyUtils
private_key = ''.join(['%x' % random.randrange(16) for x in range(0, 64)])
print keyUtils.privateKeyToWif(private_key)
print keyUtils.keyToAddr(private_key)


i know random number/string generated using this method is not very much secure, but i am talking in terms of valid WIF and address pair.
you need to make sure that the private is lower than 1.158 * 10^77 (115792089237316195423570985008687907852837564279074904382605163141518161494337) and 

In your case you could do 

 import random, keyUtils 
 private_key = ''.join(['%x' %random.randrange(16) for x in range(0, 64)]) 
 print keyUtils.privateKeyToWif(private_key)
 print keyUtils.keyToAddr(private_key)

 from ecdsa.curves import SECP256k1
 decoded_private_key = int(private_key,16)
 if decoded_private_key &gt; 0 and  decoded_private_key &lt; SECP256k1.generator.order():
     print 'valid'
 else:
     print 'invalid'