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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:25:57+00:00 2026-06-11T07:25:57+00:00

I need to generate pseudo-random codes for people to use to access my site.

  • 0

I need to generate pseudo-random codes for people to use to access my site. I wrote some code to allow this, but didn’t realize that I was using character arrays and NOT integers as the seed (to make mt_rand repeatable). My demo code is here:

$seedVal = array(6565866669, 6565866670, 6565866671);


foreach ($seedVal as $seed) {
    mt_srand($seed);
    $rnd = '';
    for ($i = 0; $i < 11; $i++) { // Loop over the string length
        $tmp = mt_rand(0, 10);
        $rnd .= $tmp;
    }

    echo "Seed = $seed, RandNum = $rnd </br>";
}

echo "</br>Now with character seeds</br>";

$seedVal = array('6565866669', '6565866670', '6565866671');

foreach ($seedVal as $seed) {
    mt_srand($seed);
    $rnd = '';
    for ($i = 0; $i < 11; $i++) { // Loop over the string length
        $tmp = mt_rand(0, 10);
        $rnd .= $tmp;
    }

    echo "Seed = $seed, RandNum = $rnd </br>";
}

return;

The result on 1and1 is:

Seed = 6565866669, RandNum = 425453109319 
Seed = 6565866670, RandNum = 39388593858 
Seed = 6565866671, RandNum = 891273965110 

Now with character seeds
Seed = 6565866669, RandNum = 97138956767 
Seed = 6565866670, RandNum = 97138956767 
Seed = 6565866671, RandNum = 97138956767 

But everywhere else, the result (localhost, other servers, etc.) is:

Seed = 6565866669, RandNum = 425453109319
Seed = 6565866670, RandNum = 39388593858
Seed = 6565866671, RandNum = 891273965110

Now with character seeds
Seed = 6565866669, RandNum = 425453109319
Seed = 6565866670, RandNum = 39388593858
Seed = 6565866671, RandNum = 891273965110 

The problem is that on my present server (1and1) the system works fine (using the unpredictable character inputs). But I’m migrating to a new server and, of course, the codes look like the first set ALWAYS. In other words, I do not know how to generate the second set of random numbers (seeded with character arrays).

Can anyone tell me how to do this?

I want:

mt_srand('6565866669');
echo mt_rand(0, 10);

to return

97138956767

Struggling. Thank you!!

  • 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-11T07:25:59+00:00Added an answer on June 11, 2026 at 7:25 am

    (Credit to therefromhere has pinpointed the issue: you have a 32 bit and a 64 bit server. Acccept his answer if he posts it)

    This is your issue:

    1. mt_srand() takes an integer paramter
    2. PHP will (helpfully) try to cast your string as an integer when required for a parameter
    3. The maximum integer on 64 bit systems is 4.something gazillion – so your string will convert to an integer, but on 32bit systems, the maximum integer is 2.1 billion, so your string will convert to a different integer withing the allowed range (it goes to 2.1 billion, then wraps to -2.1 billion and counts up and repeats).

    Solutions for handling big_ints are to use GMP or BCMath libraries, but these won’t work in this case at the mt_srand() takes an integer – so you’re limited to numbers between -2.1 billion and +2.1 billion, or installing 64 bit OS/Apache/PHP on your web server.

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

Sidebar

Related Questions

I need to generate a controlled sequence of pseudo-random numbers, given an initial integer
I need to generate a (pseudo) random sequence of N bit integers, where successive
I need to be able to generate a single random number and then use
I need to generate a controlled sequence of pseudo-random numbers, given an initial parameter.
I need to generate pseudo-random numbers for my genetic algorithm on a Spartan-3E FPGA
I need to generate a deterministic (i.e. repeatable) sequence of pseudo-random numbers given an
I need generate action links outside controllers. I can use Html.Action in Views, Url.Action
I need to generate css based on client queries. I use the @import url()
I need to generate some token that can only take on a range of
I need to generate Entities/Object from selected tables - not all. Is this possible

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.