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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:03:52+00:00 2026-06-18T10:03:52+00:00

I was reading up on this : http://www.cplusplus.com/reference/algorithm/random_shuffle/ and wondered if its possible to

  • 0

I was reading up on this : http://www.cplusplus.com/reference/algorithm/random_shuffle/
and wondered if its possible to random_shuffle an array of int elements. This is my code

#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int a[10]={1,2,3,4,5,6,7,8,9,10};

    cout << a << endl << endl;

    random_shuffle(a[0],a[9]);

    cout<<a;
}

I got this error:

error C2893: Failed to specialize function template
    'iterator_traits<_Iter>::difference_type *std::_Dist_type(_Iter)'.

My question are:

  1. Is it possible to shuffle an int array using random_shuffle. If yes, I would like to learn how to do it.

  2. Is random_shuffle only applicable to templates?

  3. What does my error mean?

  • 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-18T10:03:54+00:00Added an answer on June 18, 2026 at 10:03 am

    You need to pass pointers to a[0] and a[10], not the elements themselves:

    random_shuffle(&a[0], &a[10]); // end must be 10, not 9
    

    In C++11, you can use std::begin and std::end:

    random_shuffle(std::begin(a), std::end(a));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am reading this page http://www.cplusplus.com/doc/tutorial/exceptions.html it says if i write function() throw(); no
Just finished reading this blog post: http://www.skorks.com/2010/03/an-interview-question-that-prints-out-its-own-source-code-in-ruby/ In it, the author argues the case
I was reading this article on Coding Horror: http://www.codinghorror.com/blog/2008/04/setting-up-subversion-on-windows.html I went to the downloads
Check this example before reading the question - http://www.sqlfiddle.com/#!2/fcf3e/8 The following data comes from
So I started reading this book: http://www.amazon.com/Cocoa-Design-Patterns-Erik-Buck/dp/0321535022 On chapter 2 it explains about the
I was reading this document: http://www.fadden.com/techmisc/hdc/lesson11.htm In it he stated: Problem is, we don't
I was reading this tutorial from the DNN website http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryId/2675/DotNetNuke-Skinning-101-Part-2.aspx I found the tutorial
I am reading this document to learn Perl's taint mode => http://www.webreference.com/programming/perl/taint/index.html It is
I'm reading this article: http://www.codeproject.com/Articles/479635/UnderstandingplusandplusImplementingplusDecoratorp I'm thinking of implementing this pattern in a school
I've been reading this reference: http://www.osdever.net/FreeVGA/vga/vgafx.htm to learn VGA programming, but because I'm a

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.