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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:05:09+00:00 2026-06-09T12:05:09+00:00

well i have a use for rand(); I need to rand from 1 to

  • 0

well i have a use for rand();
I need to rand from 1 to x amount 4 times and make sure the value will not return.

This is my code corrently:

 $Count = 15;
 $secondstage = '';
 $arrayindex = '';
 for($i=1; $i<5; $i++){
    $arrayindex = rand(1,$Count);
    if($secondstage == $arrayindex){
        for($b=1; $arrayindex == $secondstage; $b++){
            $arrayindex = rand(1,$Count);
        }
    }
    $secondstage = $arrayindex;
    echo $secondstage;
    echo '<br>';
 }

Am I having some logic mistake here? I thought of maybe using while but for should also work.

  • 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-09T12:05:11+00:00Added an answer on June 9, 2026 at 12:05 pm

    So basically you want 4 random non-repeating numbers between 1 and 15, inclusive? You’re using way too much code for that. A simpler version:

    $numbers = array();
    do {
       $possible = rand(1,15);
       if (!isset($numbers[$possible])) {
          $numbers[$possible] = true;
       }
    } while (count($numbers) < 4);
    print_r(array_keys($numbers));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

well i do not know how to use sql union properly . i have
I have come across scripts that use: isset($_POST['submit']) as well as code that uses:
I have a USB GSM device which I use for Internet connection as well
well i have a configuration like this in the components part of my config
Well i have a div tag that i show as a modal dialog this
http://www.docjar.com/html/api/org/apache/catalina/realm/JDBCRealm.java.html To use this JDBCRealm we need two tables, user and user_role. user table
I have a rails application with User and Machine data models, as well as
Well i have a web page hosted in a IIS 7.0 now the problem
well I have that problem, im using a lightbox srcipt and im opening an
Well i have a form in site where people submit domains to my database,

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.