hacía un tiempo había creado una optimización para un código que permitía obtener números flotantes aleatorios, que se usaban en una funcionalidad de un hack para Counter-Strike.
En realidad se necesitan 4 valores aleatorios para usarse en el hack y lo que hice fue optimizar el código original, que daba muchas vueltas antes de hacer la operación real. Supongo que para confundir a los hackers XD
pero fuera de lo que tiene que ver con el Counter-Strike, esto sirve para generar números aleatorios (de punto flotante), por eso el título..
Tengan en cuenta que se puede modificar la función que genera los números aleatorios, para que devuelva un sólo número en lugar de un vector de 4. También pueden hacer las modificaciones que quieran, pero tengan en cuenta que así como está es como sirve para el hack.
Para más información:
http://www.gamedeception.net/threads/26109-85-Customized-Spread-Class
Este es un programa demostrativo que hice para ver los resultados:
Código:
//
// By 85
// Credits: HL1 SDK, Paul Upton, Snipity (Tad)
// elhacker.net
// etalking.com.ar
// David Riedel
// 2013
#pragma warning(disable: 4390)
#include<windows.h>
#include<iostream>
#include<stdio.h>
#include<time.h>
//
class Random{
public:
Random()
{
Init();
}
private:
void Init();
float RandomFloat[4];
unsigned int glSeed;
unsigned int seed_table[ 256 ];
public:
void SetRandomFloatVector(unsigned int seed, int future);
float* getRandomFloatVector() { return RandomFloat; }
};
//
Random random;
//
void Random::Init(){
glSeed = 0;
int i=0;
seed_table[i] = 28985; i++;
seed_table[i] = 27138; i++;
seed_table[i] = 26457; i++;
seed_table[i] = 9451; i++;
seed_table[i] = 17764; i++;
seed_table[i] = 10909; i++;
seed_table[i] = 28790; i++;
seed_table[i] = 8716; i++;
seed_table[i] = 6361; i++;
seed_table[i] = 4853; i++;
seed_table[i] = 17798; i++;
seed_table[i] = 21977; i++;
seed_table[i] = 19643; i++;
seed_table[i] = 20662; i++;
seed_table[i] = 10834; i++;
seed_table[i] = 20103; i++;
seed_table[i] = 27067; i++;
seed_table[i] = 28634; i++;
seed_table[i] = 18623; i++;
seed_table[i] = 25849; i++;
seed_table[i] = 8576; i++;
seed_table[i] = 26234; i++;
seed_table[i] = 23887; i++;
seed_table[i] = 18228; i++;
seed_table[i] = 32587; i++;
seed_table[i] = 4836; i++;
seed_table[i] = 3306; i++;
seed_table[i] = 1811; i++;
seed_table[i] = 3035; i++;
seed_table[i] = 24559; i++;
seed_table[i] = 18399; i++;
seed_table[i] = 315; i++;
seed_table[i] = 26766; i++;
seed_table[i] = 907; i++;
seed_table[i] = 24102; i++;
seed_table[i] = 12370; i++;
seed_table[i] = 9674; i++;
seed_table[i] = 2972; i++;
seed_table[i] = 10472; i++;
seed_table[i] = 16492; i++;
seed_table[i] = 22683; i++;
seed_table[i] = 11529; i++;
seed_table[i] = 27968; i++;
seed_table[i] = 30406; i++;
seed_table[i] = 13213; i++;
seed_table[i] = 2319; i++;
seed_table[i] = 23620; i++;
seed_table[i] = 16823; i++;
seed_table[i] = 10013; i++;
seed_table[i] = 23772; i++;
seed_table[i] = 21567; i++;
seed_table[i] = 1251; i++;
seed_table[i] = 19579; i++;
seed_table[i] = 20313; i++;
seed_table[i] = 18241; i++;
seed_table[i] = 30130; i++;
seed_table[i] = 8402; i++;
seed_table[i] = 20807; i++;
seed_table[i] = 27354; i++;
seed_table[i] = 7169; i++;
seed_table[i] = 21211; i++;
seed_table[i] = 17293; i++;
seed_table[i] = 5410; i++;
seed_table[i] = 19223; i++;
seed_table[i] = 10255; i++;
seed_table[i] = 22480; i++;
seed_table[i] = 27388; i++;
seed_table[i] = 9946; i++;
seed_table[i] = 15628; i++;
seed_table[i] = 24389; i++;
seed_table[i] = 17308; i++;
seed_table[i] = 2370; i++;
seed_table[i] = 9530; i++;
seed_table[i] = 31683; i++;
seed_table[i] = 25927; i++;
seed_table[i] = 23567; i++;
seed_table[i] = 11694; i++;
seed_table[i] = 26397; i++;
seed_table[i] = 32602; i++;
seed_table[i] = 15031; i++;
seed_table[i] = 18255; i++;
seed_table[i] = 17582; i++;
seed_table[i] = 1422; i++;
seed_table[i] = 28835; i++;
seed_table[i] = 23607; i++;
seed_table[i] = 12597; i++;
seed_table[i] = 20602; i++;
seed_table[i] = 10138; i++;
seed_table[i] = 5212; i++;
seed_table[i] = 1252; i++;
seed_table[i] = 10074; i++;
seed_table[i] = 23166; i++;
seed_table[i] = 19823; i++;
seed_table[i] = 31667; i++;
seed_table[i] = 5902; i++;
seed_table[i] = 24630; i++;
seed_table[i] = 18948; i++;
seed_table[i] = 14330; i++;
seed_table[i] = 14950; i++;
seed_table[i] = 8939; i++;
seed_table[i] = 23540; i++;
seed_table[i] = 21311; i++;
seed_table[i] = 22428; i++;
seed_table[i] = 22391; i++;
seed_table[i] = 3583; i++;
seed_table[i] = 29004; i++;
seed_table[i] = 30498; i++;
seed_table[i] = 18714; i++;
seed_table[i] = 4278; i++;
seed_table[i] = 2437; i++;
seed_table[i] = 22430; i++;
seed_table[i] = 3439; i++;
seed_table[i] = 28313; i++;
seed_table[i] = 23161; i++;
seed_table[i] = 25396; i++;
seed_table[i] = 13471; i++;
seed_table[i] = 19324; i++;
seed_table[i] = 15287; i++;
seed_table[i] = 2563; i++;
seed_table[i] = 18901; i++;
seed_table[i] = 13103; i++;
seed_table[i] = 16867; i++;
seed_table[i] = 9714; i++;
seed_table[i] = 14322; i++;
seed_table[i] = 15197; i++;
seed_table[i] = 26889; i++;
seed_table[i] = 19372; i++;
seed_table[i] = 26241; i++;
seed_table[i] = 31925; i++;
seed_table[i] = 14640; i++;
seed_table[i] = 11497; i++;
seed_table[i] = 8941; i++;
seed_table[i] = 10056; i++;
seed_table[i] = 6451; i++;
seed_table[i] = 28656; i++;
seed_table[i] = 10737; i++;
seed_table[i] = 13874; i++;
seed_table[i] = 17356; i++;
seed_table[i] = 8281; i++;
seed_table[i] = 25937; i++;
seed_table[i] = 1661; i++;
seed_table[i] = 4850; i++;
seed_table[i] = 7448; i++;
seed_table[i] = 12744; i++;
seed_table[i] = 21826; i++;
seed_table[i] = 5477; i++;
seed_table[i] = 10167; i++;
seed_table[i] = 16705; i++;
seed_table[i] = 26897; i++;
seed_table[i] = 8839; i++;
seed_table[i] = 30947; i++;
seed_table[i] = 27978; i++;
seed_table[i] = 27283; i++;
seed_table[i] = 24685; i++;
seed_table[i] = 32298; i++;
seed_table[i] = 3525; i++;
seed_table[i] = 12398; i++;
seed_table[i] = 28726; i++;
seed_table[i] = 9475; i++;
seed_table[i] = 10208; i++;
seed_table[i] = 617; i++;
seed_table[i] = 13467; i++;
seed_table[i] = 22287; i++;
seed_table[i] = 2376; i++;
seed_table[i] = 6097; i++;
seed_table[i] = 26312; i++;
seed_table[i] = 2974; i++;
seed_table[i] = 9114; i++;
seed_table[i] = 21787; i++;
seed_table[i] = 28010; i++;
seed_table[i] = 4725; i++;
seed_table[i] = 15387; i++;
seed_table[i] = 3274; i++;
seed_table[i] = 10762; i++;
seed_table[i] = 31695; i++;
seed_table[i] = 17320; i++;
seed_table[i] = 18324; i++;
seed_table[i] = 12441; i++;
seed_table[i] = 16801; i++;
seed_table[i] = 27376; i++;
seed_table[i] = 22464; i++;
seed_table[i] = 7500; i++;
seed_table[i] = 5666; i++;
seed_table[i] = 18144; i++;
seed_table[i] = 15314; i++;
seed_table[i] = 31914; i++;
seed_table[i] = 31627; i++;
seed_table[i] = 6495; i++;
seed_table[i] = 5226; i++;
seed_table[i] = 31203; i++;
seed_table[i] = 2331; i++;
seed_table[i] = 4668; i++;
seed_table[i] = 12650; i++;
seed_table[i] = 18275; i++;
seed_table[i] = 351; i++;
seed_table[i] = 7268; i++;
seed_table[i] = 31319; i++;
seed_table[i] = 30119; i++;
seed_table[i] = 7600; i++;
seed_table[i] = 2905; i++;
seed_table[i] = 13826; i++;
seed_table[i] = 11343; i++;
seed_table[i] = 13053; i++;
seed_table[i] = 15583; i++;
seed_table[i] = 30055; i++;
seed_table[i] = 31093; i++;
seed_table[i] = 5067; i++;
seed_table[i] = 761; i++;
seed_table[i] = 9685; i++;
seed_table[i] = 11070; i++;
seed_table[i] = 21369; i++;
seed_table[i] = 27155; i++;
seed_table[i] = 3663; i++;
seed_table[i] = 26542; i++;
seed_table[i] = 20169; i++;
seed_table[i] = 12161; i++;
seed_table[i] = 15411; i++;
seed_table[i] = 30401; i++;
seed_table[i] = 7580; i++;
seed_table[i] = 31784; i++;
seed_table[i] = 8985; i++;
seed_table[i] = 29367; i++;
seed_table[i] = 20989; i++;
seed_table[i] = 14203; i++;
seed_table[i] = 29694; i++;
seed_table[i] = 21167; i++;
seed_table[i] = 10337; i++;
seed_table[i] = 1706; i++;
seed_table[i] = 28578; i++;
seed_table[i] = 887; i++;
seed_table[i] = 3373; i++;
seed_table[i] = 19477; i++;
seed_table[i] = 14382; i++;
seed_table[i] = 675; i++;
seed_table[i] = 7033; i++;
seed_table[i] = 15111; i++;
seed_table[i] = 26138; i++;
seed_table[i] = 12252; i++;
seed_table[i] = 30996; i++;
seed_table[i] = 21409; i++;
seed_table[i] = 25678; i++;
seed_table[i] = 18555; i++;
seed_table[i] = 13256; i++;
seed_table[i] = 23316; i++;
seed_table[i] = 22407; i++;
seed_table[i] = 16727; i++;
seed_table[i] = 991; i++;
seed_table[i] = 9236; i++;
seed_table[i] = 5373; i++;
seed_table[i] = 29402; i++;
seed_table[i] = 6117; i++;
seed_table[i] = 15241; i++;
seed_table[i] = 27715; i++;
seed_table[i] = 19291; i++;
seed_table[i] = 19888; i++;
seed_table[i] = 19847;
}
//
// Misma funcionalidad que random.cpp y nospread.cpp (Snipity Hook)
void Random::SetRandomFloatVector(unsigned int seed, int future){// By 85
for(int i=0; i<4; i++){
glSeed = seed_table[(int)(seed+future+i)&0xff];
for(int j=0; j<3;j++){
glSeed *= 69069;
glSeed += seed_table[glSeed&0xff];
(++glSeed & 0x0fffffff);
}
RandomFloat[i]=(-0.5+(float)(((glSeed&0x0fffffff)&65535)/65536.0f));
}
}
//
int main(){
unsigned int seed;
int future;
seed = time(NULL);
future=1;
int i =0;
while(1)
{
seed = time(NULL);//No es la seed original (Original es me.spread.random_seed)
random.SetRandomFloatVector(seed, future);
printf("RandomFloat[0] %f\n",random.getRandomFloatVector()[0]);
printf("RandomFloat[1] %f\n",random.getRandomFloatVector()[1]);
printf("RandomFloat[2] %f\n",random.getRandomFloatVector()[2]);
printf("RandomFloat[3] %f\n",random.getRandomFloatVector()[3]);
printf("\n");
std::cout << "Press the ENTER key\n";
if (std::cin.get() == '\n');
if(i++==10) break;
}
system("pause > nul");
return 0;
}
//
Proyecto vc6: http://www.mediafire.com/?a93dsydc3gvrrdj