Created
January 22, 2021 04:36
-
-
Save Ts-Pytham/860f10558365e8677e4e6d38498a5c75 to your computer and use it in GitHub Desktop.
Algoritmo Congruencial Aditivo
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" | |
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; | |
} | |
} | |
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" | |
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; | |
} |
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
#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