in your cart object, you should have a column to hold the gift card number.
Go to the bindings panel, and click the plus button. Select Security Assist -> Random Password to add the random password binding.
In the add to cart button, set the Gift card number to be editable from a hidden form element.
after the add to cart button is added to the page, select the gift card hidden element, in the property inspector, click the lightning bolt icon next to Initial value. Select the random pass word binding.
The gift card in to needs to be added to the database during checkout into the order details table. you can get the gift card number form the order details table.
your last question is going to take some custom development, it will require hand coding php and creating a complex SQL query. I would recommend signing up for a premiere ticket appointment where we could work with you in a one on one session to implement this.