Skip to content

Instantly share code, notes, and snippets.

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