Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8496561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:53:19+00:00 2026-06-10T23:53:19+00:00

How to make my id generator code elegant : When a user registers they

  • 0

How to make my id generator code elegant: When a user registers they get an id.. What is the chance that the id generated will NOT be unique? Also – How can i make my code elegant?
THANKS!

#hash = random url generated from 128 chars

$cac = substr($hash, 64,-60);

$words = array('GET', 'COOL', 'WOW', 'YES', 'NICE', 'BUCK', 'LUCK', 'FUN', 'CASH', 'TIP', 'PEEK', 'TAG'); 
$rword = rand(0,11);

$syms = array('-', '#', '$', '@');
$rsym = rand(0,3); 

$nums = rand(0,9);

$aff_id_temp = $words[$rword] . $syms[$rsym] . $cac . $nums;
$final_id = strtoupper($aff_id_temp);

—UPDATE—
The code works. Just need to generate a simple affiliate id for users when they register. By elegant I mean – perhaps the way I am hacking out the final product code be done more simply or in a different way (perhaps in a loop) basically I want to learn different ways to achieve the same result. I want other coding perspectives.

The output is something like: TIP#6C1D2

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T23:53:20+00:00Added an answer on June 10, 2026 at 11:53 pm

    Practically zero, due to the hash. That said, it depends entirely on the hash function.

    Excluding the hash, the chance of any given id colliding with another given id is 1/(12*4*10) = 1/480, roughly 0.2%. However, the chance of a new id not colliding with any other id is 1-(1-1/480)^c, where c is the number of ids you already have. With just 50 ids you already have a 10% chance of collision.

    You can get a unique hash with the uniqid function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a simple generator that takes some syllables from a user
I am writing a code-generator that will need to output some miniscule portions of
i've tried using this code and this to make a random quote generator, but
How can I make sure the CS generated from code like the following is
I'm trying to make a truth-table generator for a digital electronics course because that's
I wanted to make a generator that created files (and directories, etc...) based on
I'm creating a bubble generator as a background effect that will run on a
I am trying to make a generator function that yields an item on each
I want to build a simple code generator in java that can take database
I've written an interface to the code generator that lets me produce shared objects.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.