PHP: Random sequence function

Here is a function I have created which is used to generate a sequence of random numbers, letters and symbols. I currently use it on a number of projects including http://passworded.co.uk which is a simple password generator.

How to use

Function

How it works

The function can be adjusted to allow different characters and symbols to be generated in a sequence, there is a variable (array) called $seq_possibilities, you simply adjust the data which is first added into this array to the characters and symbols you want to be used in your sequences.

The function works by looping the specified number of times (when you call the function you pass the size of the sequence you require), on every loop it will use the rand() function and generate a number between zero and the size of $seq_possibilities array, the array data will then be pulled out of the array and placed onto the end of the $sequence variable. After it has loop enough times we will return the generated sequence.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.