Created
January 22, 2021 04:50
-
-
Save Ts-Pytham/d946379385d612f8da31375afc1eafb6 to your computer and use it in GitHub Desktop.
Algoritmo Congruencial aditivo en C++ usando la clase vector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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