C
C#2w 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
canton72w ago
Do you have a list of IDs which you have generated already?
Angius
Angius2w ago
Sequential IDs masked with sqids Maybe nanoid with limited size and custom alphabet
canton7
canton72w ago
The most trivial algorithm is do { id = GenerateRandomNumber(); } while (!AlreadyGenerated(id));
Angius
Angius2w ago
Or current UNIX timestamp + random value
workani
workaniOP2w 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
Angius2w 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
workaniOP2w ago
In method that I speaking about no Thanks!
Want results from more Discord servers?
Add your server