C
C#3mo 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
canton73mo ago
Do you have a list of IDs which you have generated already?
Angius
Angius3mo ago
Sequential IDs masked with sqids Maybe nanoid with limited size and custom alphabet
canton7
canton73mo ago
The most trivial algorithm is do { id = GenerateRandomNumber(); } while (!AlreadyGenerated(id));
Angius
Angius3mo ago
Or current UNIX timestamp + random value
workani
workaniOP3mo 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
Angius3mo 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
workaniOP3mo ago
In method that I speaking about no Thanks!

Did you find this page helpful?