-1

I have two variables R and S. I defined them as int R[1000] and int S[100000]. R will hold the values from 0 to 999. Now, I want the R values to be uniformly distributed in S (100000 values ). The number of entries in S should be 100000 but they should be uniformly distributed in the range of 0-999.

How can I do this?

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85

1 Answers1

2

You can write something like the following to populate R and S quickly using the C++11 STL:

#include <numeric>
#include <random>

int main() {
    int R[1000], S[100000];
    std::iota( std::begin( R ), std::end( R ), 0 );
    std::mt19937 engine;
    std::uniform_int_distribution<int> dist( 0, 999 );
    std::generate( std::begin( S ), std::end( S ), []{ return dist( engine ); } );
}
Thomas Russell
  • 5,870
  • 4
  • 33
  • 68