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 9124969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:41:29+00:00 2026-06-17T06:41:29+00:00

I have to generate a unique and random string which is to be stored

  • 0

I have to generate a unique and random string which is to be stored in database. For doing this I have used the “uuidtools” gem. Then in my controller I have added the following line:

require "uuidtools"

and then in my controllers create method I have declared a ‘temp’ variable and generating a unique and random ‘uuid’ string like this:

temp=UUIDTools::UUID.random_create

which is creating a string like this one:

f58b1019-77b0-4d44-a389-b402bb3e6d50

Now my problem is I have to make it short, preferably within 8-10 character. Now how do I do it?? Is it possible to pass any argument to make it a desirable length string??

Thanks in Advance…

  • 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-17T06:41:31+00:00Added an answer on June 17, 2026 at 6:41 am

    You don’t need uuidtools for this. You can use Secure Random for this.

    [1] pry(main)> require "securerandom"
    => true
    [2] pry(main)> SecureRandom.hex(20)
    => "82db4d707c4c5db3ebfc349da09c991b7ca0faa1"
    [3] pry(main)> SecureRandom.base64(20)
    => "CECjUqNvPBaq0o4OuPy8RvsEoCY="
    

    Passing 4 and 5 to hex will generate 8 and 10 character hex strings respectively.

    [5] pry(main)> SecureRandom.hex(4)
    => "a937ec91"
    [6] pry(main)> SecureRandom.hex(5)
    => "98605bb20a"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a function that will generate a random string which works fine.
I have an object for which I want to generate a unique hash (override
What java library are there provides the the facility to generate unique random string
How would it be possible to generate a random, unique string using numbers and
I want to generate unique and random numbers or IDs which I can use
I want to generate a 9 digit unique random string. Currently I am using
I have to generate unique ID depending on time, counter and random prepended value
I have a need to generate a random SecretKey, in Java, which I will
I need to generate a unique random code to store in a database with
Possible Duplicate: PHP: How to generate a random, unique, alphanumeric string? I'm creating the

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.