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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:23:38+00:00 2026-05-26T17:23:38+00:00

I created a function to create a random matrix containing 0 and 1 in

  • 0

I created a function to create a random matrix containing 0 and 1 in C++ using srand and rand
but i didn’t know how can I specify that in each matrix i need the same number of 1 for example 5.
I thought of putting a variable that counts the number of 1 and if they are less or more then 5 to adjust the matrix, but i was wondering if there’s a much faster solution.thanks

  • 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-26T17:23:38+00:00Added an answer on May 26, 2026 at 5:23 pm

    Create a vector with the same number of elements as the matrix, containing the appropriate number of 1s at the beginning, and all 0s at the end. Then random_shuffle this vector, and copy the elements into a matrix.

    (I routinely use this to generate adjacency matrices of random graphs with a fixed number of edges.)

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

Sidebar

Related Questions

This is a Function that does the following: Create a random Token with 8
I'm trying to create a captcha code but the code that is being created
I want to create a dynamic 2d array by function but it seems that
I created the following function to simplify a piece of particularly complex code. CREATE
I have a question regarding an update function I created... CREATE OR REPLACE FUNCTION
we are trying to create a calendar function in python. we have created a
I can create function pointers in Fortran 90, with code like real, external ::
How to create a function, which on every call generates a random integer number?
Following this nice example I found, I was trying to create a function that
I want create a function that verify if the numbers of a list fall

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.