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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:44:47+00:00 2026-05-12T18:44:47+00:00

i need to print out numbers 1-100 in a random order. the print statement

  • 0

i need to print out numbers 1-100 in a random order. the print statement should be:

echo ‘h{‘.$num.’}’;

what is the shortest code to do this?

  • 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-12T18:44:47+00:00Added an answer on May 12, 2026 at 6:44 pm

    The easiest way is to use shuffle with an array containing the 100 numbers

    e.g.

    $sequence = range(1, 100);
    shuffle($sequence);
    foreach ($sequence as $num) {
        echo 'h{'.$num.'}';
    }
    

    Also see the range function

    EDIT

    I thought I might add a little on what shuffle does. Although php.net doesn’t explicitly say so, it is likely based on the modern version of the Fisher-Yates shuffle algorithm. For a video demonstration of how it works, see http://www.youtube.com/watch?v=Ckh2DJrP7F4. Also see this excellent flash demonstration

    The shuffle algorithm essentially works like this:

    1. For a given set of elements A1 to AN, and n = N;
    2. Randomly select an element Ak between A1 and An inclusive
    3. Swap Ak and An
    4. Set n = n – 1
    5. Repeat from step 2

    Hope that helps.

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

Sidebar

Related Questions

I need to print out a second array, that takes the numbers from the
This c++ code prints out the following prime numbers: 3 5 7 11 13
I need to print out data into a pre-printed A6 form (1/4 the size
The following code, prints out Derived Base Base But I need every Derived object
I have occasion to need to print code (Horrors!!! ;) ), and i was
I need to write a PHP script that will print out results from a
I'm using Java's DecimalFormat class to print out numbers in Scientific Notation. However, there
I need for my output to be the first 100 pentagonal numbers, ten per
At some point I need to display a disabled (greyed out by disabled=disabled attribute)
I need to print the date in the format of mm/dd/yyyy. if the date

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.