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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:46:56+00:00 2026-05-20T00:46:56+00:00

I am using the following to generate a near random number. 3> erlang:ref_to_list(make_ref()). #Ref<0.0.0.36>

  • 0

I am using the following to generate a near random number.

3> erlang:ref_to_list(make_ref()).

"#Ref<0.0.0.36>"

What I want is 00036

Well it was what I had been informed I could do in a previous post. It occurred to me that it is not so easy to extract the numbers from make ref.

Can anyone show how it is easily done, or possibly recommend another solution.

Keep in mind that using random:seed() is not random when called within the same few nano seconds.

Regards

  • 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-05-20T00:46:57+00:00Added an answer on May 20, 2026 at 12:46 am

    Note: from OTP 18 erlang:now/0 and random module are deprecated, and OTP 20 will remove the random module. See Time and Time Correction in Erlang for the further details. Also, you no longer need to do the per-process seeding if you use rand:uniform/0. The following is left as is for reference.


    The problem is that you are using random incorrectly. random:seed/0 will seed the random number generator with the very same seed always. This is not good for what you want. Rather, you can use random:seed(erlang:now()) to seed it with another number, namely the current time.

    “What happens if two calls come very close?” you may ask. Well, the Erlang guys thought about this, so now/0 is guaranteed to always return increasing numbers:

    Returns the tuple {MegaSecs, Secs, MicroSecs} which is the
    elapsed time since 00:00 GMT, January 1, 1970 (zero hour) on the
    assumption that the underlying OS supports this. Otherwise, some
    other point in time is chosen. It is also guaranteed that subse‐
    quent calls to this BIF returns continuously increasing values.

    Hence, the return value from now() can be used to generate
    unique time-stamps, and if it is called in a tight loop on a
    fast machine the time of the node can become skewed.

    (emphasis mine)

    Also note that the random PRNG is per-process, so you should always start your process up with a seeder call:

    init([..]) ->
      random:seed(erlang:now()),
      [..]
      {ok, #state { [..] }}.
    

    Using references for this is perhaps possible, but I don’t think it is a viable one. The solution goes over erlang:ref_to_list/1 and it is not pretty.

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

Sidebar

Related Questions

I'm using the following code to generate a random string: <?php function random_string( )
I'm using the following statement to generate random dates: DATEADD(day, DATEDIFF(day, 1, GETDATE()) -
Am using the following program for generate the Token,based on the time(current time).It was
I am using the following code to generate excel from sql through php.this is
I am using the following code to generate a histogram chart using YUI charts:
I am using the following code to generate an encrypted token: var ticket =
I am using the following code to generate a Buy Now button for selling
I am using the following Spreadsheet gem to generate an excel sheet from ruby-on-rails..
I'm using the following code which will generate a wav file which contains a
I was wondering how can I generate the following array using ranges in ruby

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.