Skip to content

Commit

Permalink
fix: Normal mode now generate random id correctly (#25)
Browse files Browse the repository at this point in the history
Co-authored-by: __hidehalo <[email protected]>
  • Loading branch information
betaSavvy and hidehalo authored Dec 30, 2021
1 parent a1890e0 commit 3229400
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private function normalRandom($size)
$id = '';
while (1 <= $size--) {
$rand = mt_rand()/(mt_getrandmax() + 1);
$id .= $this->alphabet[$rand*64 | 0];
$id .= $this->alphabet[intval($rand*64)];
}

return $id;
Expand Down
2 changes: 2 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ public function testGenerateId(Client $client)
$size = 7;
$normalRandom = $client->generateId($size);
$this->assertEquals($size, strlen($normalRandom));
$this->assertNotEquals(str_repeat('_', $size), $normalRandom);
$dynamicRandom = $client->generateId($size, Client::MODE_DYNAMIC);
$this->assertEquals($size, strlen($dynamicRandom));
$this->assertNotEquals($normalRandom, $dynamicRandom);
$defaultRandom = $client->generateId();
$this->assertEquals(21, strlen($defaultRandom));
$this->assertNotEquals(str_repeat('_', 21), $defaultRandom);
}

/**
Expand Down

0 comments on commit 3229400

Please sign in to comment.