PHP: Generating Multiple Random String

Here is a quick way to generate random strings in PHP. I will be showing how you can generate multiple random strings at once. You can specify the number of letters in the random string generated. You can also specify the total number of words you want to generate. I have used str_shuffle function to … Read more

Magento: Set Random Order in Collection using RAND()

Scenario: You have created a custom module. You have entered certain data in your database. You need to show the data randomly. Solution: In MySQL the rand() function helps the select query to fetch data randomly. In Magento, you can select random rows from MySQL table using Zend_Db_Expr(‘RAND()’). You have to create a new function … Read more

PHP: Generate random number and string

Here are code samples to generate random number and strings in PHP. Generate random numbers between 1 and 1000 $num = rand(1,1000); Using mtrand() function for better random number generation $num = mt_rand(1,1000); Generate a unique combination of numbers and letters. Works with PHP5 and higher. $unique = uniqid(); Using md5() and uniqid() function to … Read more