I have created attribute for products using following code in magento root
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
foreach(Mage::getModel('catalog/product')->getCollection() as $product)
{
$num= $product->getId();
$test=generateEAN($num); //this is the values i have to set for the custom attribute of each product
$installer = new Mage_Sales_Model_Mysql4_Setup;
$attribute = array(
'type' => 'text',
'label'=> 'test',
'input' => 'text',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => $test,// i don't know this is the correct way to assign the value to each product
'group' => "General"
);
$installer->addAttribute('catalog_product', 'testing', $attribute);
$installer->endSetup();
}