-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomizer.php
56 lines (49 loc) · 1.13 KB
/
randomizer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/*
* Generates a characters to display as a link
* date: 13 May 2023
* Author: Blessing G. Sithole
*
* @params len
* return chars
*/
class Randomizer{
//properties
private $len;
//methods
public function __construct($len)
{
$this->len = $len;
}
private function generator(){
$rand_chars = "";
for($i =0; $i < $this->len; $i++){
$rand_chars .= $this->chars()[(rand(0,$this->leng()-1))];
}
return $rand_chars;
}
public function getChars(){
/*
* returns characters generated at random
*/
return $this->generator();
}
private function chars()
{
/*
* returns the characters or a string with different characters
*/
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz@#!";
}
private function leng()
{
/*
* return size or length of character string
*/
return strlen($this->chars());
}
}
//instantiate
$len = 10;
$rand_link = new Randomizer($len);
echo $rand_link->getChars();