카테고리 없음

c++ 로또 번호 뽑기

Daekyue 2024. 4. 2. 16:31
#include <iostream>
#include <random>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    random_device rd;
    mt19937 gen(rd());
    uniform_int_distribution<> dis(1, 45);

    for (int i = 0; i < 5; ++i) {
        vector<int> numbers;
        while (numbers.size() < 6) {
            int num = dis(gen);
            if (find(numbers.begin(), numbers.end(), num) == numbers.end()) {
                numbers.push_back(num);
            }
        }
        sort(numbers.begin(), numbers.end());

        cout << "랜덤한 숫자 " << i + 1 << ": ";
        for (int j = 0; j < 6; ++j) {
            cout << numbers[j] << " ";
        }
        cout << endl;
    }

    return 0;
}