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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:38:27+00:00 2026-06-04T13:38:27+00:00

I am using the following code which generates random number between 0 to Totalfriends,

  • 0

I am using the following code which generates random number between 0 to Totalfriends, I would like to get the random numbers but they should not be repeated. Any idea how?

This is the code I am using

FB.getLoginStatus(function(response) {
    var profilePicsDiv = document.getElementById('profile_pics');
FB.api({ method: 'friends.get' }, function(result) {

     // var result =resultF.data;
   // console.log(result);
   var user_ids="" ;
   var totalFriends = result.length;
   // console.log(totalFriends);
   var numFriends = result ? Math.min(25, result.length) : 0;
  // console.log(numFriends);
   if (numFriends > 0) {
      for (var i=0; i<numFriends; i++) {
        var randNo = Math.floor(Math.random() * (totalFriends + 1))
        user_ids+= (',' + result[randNo]);
         console.log(user_ids);

          }
        }
        profilePicsDiv.innerHTML = user_ids;
      });
});
  • 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-04T13:38:29+00:00Added an answer on June 4, 2026 at 1:38 pm

    Here’s a function that will take n random elements from array, and return them, based off a fisher-yates shuffle. Note that it will modify the array argument.

    function randomFrom(array, n) {
        var at = 0;
        var tmp, current, top = array.length;
    
        if(top) while(--top && at++ < n) {
            current = Math.floor(Math.random() * (top - 1));
            tmp = array[current];
            array[current] = array[top];
            array[top] = tmp;
        }
    
        return array.slice(-n);
    }
    

    Assuming your code works how I think it does, you already have an array of userids:

    var random10 = randomFrom(friendIds, 10);
    
    • 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 which will generate a wav file which contains a
I'm using he following code the call a CFC which returns auto-suggest results through
I'm using the following code to post to the server which is then sent
Given the following lines of code which is using JQTOUCH: $('#customers').bind('pageAnimationEnd', function(e, info){ if
I have a javascript code using which I want to accomplish the following .
Using following code I try to get updated list of checkbuttons' corresponding text values,
I'm using the following code to generate a random string: <?php function random_string( )
In my project, legacy code generates xml which has following structure : <Output> <Template
I have the following code which generates data similar to mine. The posting here
I have the following code which generates XML: $dom = new DomDocument('1.0'); ...snip adding

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.