Add the address alias as listed above using ifconfig. Then in your code, specify your source address in the inaddr you feed to bind(), just like you do with connect(). Note that bind() will fail if the address isn't already added.
If you're not writing code, you may still be able to pull this off by using different destination addresses and adding -host routes mapping each destination address to a specific local address. Clearly this will be much more easily accomplished with a script.
If anyone knows how to add the addresses from within the program, I'd be much obliged to know.