nextapps-be / unique-codes Goto Github PK
View Code? Open in Web Editor NEWGenerate unique, random-looking codes
License: MIT License
Generate unique, random-looking codes
License: MIT License
I've read your post about the source(https://gdebrauwer.dev/blog/generating-unique-voucher-codes/). But i get different result, I don't know why?
encodeNumber(1) == 213456
encodeNumber(665281) == 24ECAD
encodeNumber(1) != encodeNumber(665281)
Can you give me the answer, thank you!
Currently, I believe a developer must specify both primes, plus the list of characters, plus any other parameters they wish to supply, each time they call UniqueCodes()
.
I use Laravel and I'd love to be able to put all those config items in a config file, so that I don't need to supply them in the main body of my code.
Does that sound like a good idea? Would the project maintainers be keen to see a PR, if I put one together?
n/a
I've a question, two primes number that you need to obfuscate sequential number, must be coprimes?
In this link:
https://web.archive.org/web/20170730030023/http://blog.mischel.com/2017/06/20/how-to-generate-random-looking-keys/
const long m = 101; // Number of keys + 1
const long x = 387420489; // must be coprime to m
Generated codes prepend the first character of the character map to fill the generated code to the requested length - or so it looks, I'm no mathematician, and thus cannot offer any help in solving it.
(new \NextApps\UniqueCodes\UniqueCodes())->setObfuscatingPrime(30402457)->setMaxPrime(25964951)->setCharacters('rn5ze6xatdkv9picsh10fm8g')->setLength(16)->generate(1, 100, true);
Output:
[
"rrrrrrrrrrrpdrr5",
"rrrrrrrrrrn51rre",
"rrrrrrrrrrnszrrx",
"rrrrrrrrrr569rrt",
"rrrrrrrrrr51mrrk",
"rrrrrrrrrrrnghgp",
"rrrrrrrrrrrcthgc",
"rrrrrrrrrrnehhgh",
"rrrrrrrrrrn15hg0",
"rrrrrrrrrr5avhgm",
"rrrrrrrrrr5ffhgg",
"rrrrrrrrrrrzgvg5",
"rrrrrrrrrrrhtvge",
"rrrrrrrrrrnxhvgx",
"rrrrrrrrrrnf5vgt",
"rrrrrrrrrr5dvvgk",
"rrrrrrrrrr58fvg9",
"rrrrrrrrrrr6g68c",
"rrrrrrrrrrr0t68h",
"rrrrrrrrrrnth680",
"rrrrrrrrrrn8568m",
"rrrrrrrrrr5vv68g",
"rrrrrrr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rrnc6h1z",
"rrrrrrrrrr5eih16",
"rrrrrrrrrr5hgh1a",
"rrrrrrrrrrrn5vhk",
"rrrrrrrrrrrivvh9",
"rrrrrrrrrrnzfvhi",
"rrrrrrrrrrnh6vhs",
"rrrrrrrrrr5xivh1",
"rrrrrrrrrr50gvhf",
"rrrrrrrrrrrz56sg",
"rrrrrrrrrrrsv6hn",
"rrrrrrrrrrn6f6hz",
"rrrrrrrrrrn066h6",
"rrrrrrrrrr5ti6ha",
"rrrrrrrrrr5mg6hd",
"rrrrrrrrrrr6ngs9",
"rrrrrrrrrrr1kgsi",
"rrrrrrrrrrna0gss",
"rrrrrrrrrrnmegs1",
"rrrrrrrrrr5kpgsf",
"rrrrrrrrrr5g8gs8",
"rrrrrrrrrrranhsn",
]
Deprecated function: Implicit conversion from float 222886.09677419355 to int loses precision in NextApps\UniqueCodes\UniqueCodes->encodeNumber() (line 227 of…/vendor/nextapps/unique-codes/src/UniqueCodes.php).
Code in UniqueCodes:227 generates a float value. This will be cast to interger for using as array key.
Just generate a code into a PHP 8.1 environment.
Cast $digit into a integer on line UniqueCodes:229
protected function encodeNumber(int $number)
{
$string = '';
$characters = $this->characters;
for ($i = 0; $i < $this->length; $i++) {
$digit = $number % strlen($characters);
$string = $characters[(int)$digit].$string;
$number = $number / strlen($characters);
}
return $string;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.