DEV Community

Cover image for Random Code Generator
Scott Windon
Scott Windon

Posted on

Random Code Generator

Wanted a nice and simple PHP class which could generate random codes. After looking at multiple libraries I found that sometimes it's best done yourself.

The final class can either generate a single code or an array of codes based on the parameters you set.

https://github.com/swindon/code-generator

Example
Generates 8 character long string

(new CodeGenerator)->generate(8);
// output: 4CF9O7XP
Enter fullscreen mode Exit fullscreen mode

Show some support!

Buy me a coffee

Top comments (0)