C
C#2mo ago
workani

✅ Creating random & unique page id

I want to generate id for a page that will be used to access it, something like example.com/2121424221. But generated id should have about 10-15 digits and be unique. How could I do that?
7 Replies
canton7
canton72mo ago
Do you have a list of IDs which you have generated already?
Angius
Angius2mo ago
Sequential IDs masked with sqids Maybe nanoid with limited size and custom alphabet
canton7
canton72mo ago
The most trivial algorithm is do { id = GenerateRandomNumber(); } while (!AlreadyGenerated(id));
Angius
Angius2mo ago
Or current UNIX timestamp + random value
workani
workaniOP2mo ago
I have Page table in my database Looks good to me. But how could I retrive list of ids from my db using EF?
Angius
Angius2mo ago
Uh Like you would retrieve anything else?
var ids = await context.Things
.Select(t => t.Id)
.ToListAsync();
var ids = await context.Things
.Select(t => t.Id)
.ToListAsync();
workani
workaniOP2mo ago
In method that I speaking about no Thanks!
Want results from more Discord servers?
Add your server