4 std::map<int, std::string> Random::productos;
5 std::map<int, std::string> Random::marcas;
7 int Random::productos_cant = 0;
8 int Random::marcas_cant = 0;
14 GetFile ("productos.txt", Random::productos, Random::productos_cant);
15 GetFile ("marcas.txt", Random::marcas, Random::marcas_cant);
18 void Random::GetFile (const char *f, std::map<int,std::string> &out, int &cant)
20 std::ifstream reader (f);
23 if (!reader.is_open ()) return;
27 while (!reader.eof ()) {
28 reader.getline (l, 100);
29 out[cant] = std::string (l);
34 void Random::Ints (std::list<int> &lst, uint n)
36 /* Genero N numeros aleatorios entre -3*n y 3*n */
37 bool *numeros = new bool [6*n+1];
40 memset (numeros, 0, (6*n+1)*sizeof (bool));
43 for (uint i=0; i < n; i++) {
45 random = 1 + (int)(6.0f * n * rand () / (RAND_MAX + 1.0f) - 3.0f * n);
46 } while (numeros[random + 3 * n] == true);
47 numeros[random + 3 * n] = true;
48 lst.push_back (random);
52 void Random::Strings (std::list<std::string> &lst, uint n)
55 /* TODO : Evitar repetidos */
56 for (uint i=0; i < n; i++) {
57 random1 = 1 + (int)(productos_cant * (float)rand () / (RAND_MAX + 1.0f));
58 random2 = 1 + (int)(marcas_cant * (float)rand () / (RAND_MAX + 1.0f));
60 lst.push_back (productos[random1-1] + " " + marcas[random2-1]);
64 double Random::Double (double min, double max)
66 return min + max * (float)rand () / (RAND_MAX + 1.0f);