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

  • Home
  • SEARCH
  • 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 6008141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:46:58+00:00 2026-05-23T01:46:58+00:00

I have an array in my PHP application, and I need to develop a

  • 0

I have an array in my PHP application, and I need to develop a function that, given the array and an arbitrary string password, will output a shuffled subset of the large array. The subset and order of the array outputted should be the same every time the same password is used to call the function.

I can generate a pseudo-random number based on the password by taking the integer value of a hash like MD5, but I’m not sure how I can use this to then:

1) Select X (either a fixed number or, preferably, a number chosen by the hash within a given range) random items from the array based on the hash

2) Shuffle/rearrange these items into a subset based on the hash

For my implementation collisions are acceptable, as the array is of a relatively small size. This is a pretty interesting problem – anyone have any idea how to tackle it?

  • 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-23T01:46:58+00:00Added an answer on May 23, 2026 at 1:46 am

    Don’t know much about the PHP implementation, but I think the general algorithm would involve seeding a pseudo-random number generator using your hash.

    Seeding a pseudo-random number generator ensures that the pseudo-random numbers you get are in the same order every time. Shuffle the array using the first pseudo-random number from the seeded generator. Then, use the next value of the pseudo-random number generator to pick a number between 1 and the size of your array; slice off these first n elements from the array.

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

Sidebar

Related Questions

What is the PHP preg_replace in C#? I have an array of string that
In PHP I can name my array indices so that I may have something
I am maintaining an OO PHP application that loads everything to $this array. When
I have an array in PHP which holds a bunch of unix timestamps. As
Say I have an array of strings in a php array called $foo with
A PHP array can have arrays for its elements. And those arrays can have
I have two arrays in PHP. The first array ($author_array) is comprised of user_ids
I have an array of numbers that potentially have up to 8 decimal places
I need to transfer the values from a PHP array into a JavaScript array
I have an application that create child's gifts applications, and every application owner can

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.