Skip to content

Instantly share code, notes, and snippets.

@Ts-Pytham
Created January 22, 2021 04:50
Show Gist options
  • Save Ts-Pytham/d946379385d612f8da31375afc1eafb6 to your computer and use it in GitHub Desktop.
Save Ts-Pytham/d946379385d612f8da31375afc1eafb6 to your computer and use it in GitHub Desktop.
Algoritmo Congruencial aditivo en C++ usando la clase vector
#include <iostream>
#include "Random.hpp"
#include <vector>
using std::vector;
int main()
{
vector<int> vect;
int data;
for (int i = 0; i != 5; ++i) {
std::cin >> data;
vect.push_back(data);
}
Random rand;
int n = 7;
int m = 100;
vector<float> vectt = rand.Randint(vect, n, m);
for (int i = 0; i != n; ++i) {
std::cout << "Valor: " << vectt[i] << std::endl;
}
}
#include "Random.hpp"
#include <vector>
using std::vector;
vector<float> Random::Randint(vector<int> vect, int n, int m) {
int tam = vect.size();
int newtam = tam + n;
vector<float> vectf;
for (int i = tam; i != newtam; ++i) {
vect.push_back((vect[i - 1] + vect[i-tam]) % m);
vectf.push_back( (float)vect[i] / (m - 1));
}
return vectf;
}
#include <vector>
#pragma once
class Random {
public:
std::vector<float> Randint(std::vector<int> vect, int n, int m);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment