Skip to content

Instantly share code, notes, and snippets.

@maneesh29s
Last active September 28, 2023 06:04
Show Gist options
  • Select an option

  • Save maneesh29s/51e1498817f2ce71be9d14a224d162fe to your computer and use it in GitHub Desktop.

Select an option

Save maneesh29s/51e1498817f2ce71be9d14a224d162fe to your computer and use it in GitHub Desktop.
Random Distribution Generator using standard library methods (c++17 and above). Random data is generated and stored in a 2D array of size 4x3.
#include <array>
#include <chrono>
#include <cstdlib>
#include <iostream>
#include <random>
using Vec3D = std::array<float, 3>;
int main() {
  std::array<Vec3D, 4> arr;
  std::random_device rd;
  std::mt19937 generator(rd());
  std::uniform_real_distribution<float> distribution(0.f, 1.f);
  for (std::size_t i = 0; i < arr.size(); ++i) {
    arr[i] = {distribution(generator), distribution(generator),
              distribution(generator)};
    std::cout << arr[i][0] << " " << arr[i][1] << " " << arr[i][2] << std::endl;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment