Randomizing a "FLOAT" (newb)

Posts 1–3 of 3 · Page 1 of 1
Randomizing a "FLOAT" (newb)
Well, I'm working on a semi-public hack and I was wondering if someone could help me randomize this float?
Code:
BOOL CEngine::AimAtRandom(CPlayer* pTarget, BOOL bRandomShot)
{
	CPlayer* LocalPlayer = PlayerList->GetLocalPlayer();
	Vec3f vAimMod = Vec3f(0.0f, 0.0f, 0.0f);
	int randmin = 0.2f; //minimum of the randomization
	int randmax = 0.7f; //maximum of the randomization

	if(LocalPlayer != NULL) {
		if(pTarget->IsCrouching) {
			vAimMod.z += 0.4f;
		}

		if(!bRandomShot) {
			if(pTarget->IsCrouching) {
				vAimMod.z += 0.2f;
			}
			else {
				vAimMod.z += 0.5f;
			}
		}

		Vec3f vNewAim = ((pTarget->Camera + vAimMod) - LocalPlayer->Camera);
		vNewAim.ModifyDirection(LocalPlayer->VForward, LocalPlayer->VUp, LocalPlayer->VRight);

		return TRUE;
	}

	return FALSE;
}
Brother of mine won't bother to help me since he's the one that's being doing it for me these past few days and I've been learning from him so, yeah.

Theory ;
Basically what I'm trying to do is for that each time I aim at the enemy it'll randomize the location of where it's going to aim at. I just can't remember how my brother did this, he did a bonescan as well but I'm a noob and can't keep up.
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>

int main() {
  std::srand(std::time(0));
  
  float offset = static_cast<float>(std::rand() % 6 + 2) / 10;
  std::cout << offset << std::endl;
}
An offset between and including 0.2 and 0.7 is randomly generated. Add/subtract this offset to whatever coordinates you want to randomize.
Quote Originally Posted by Fovea View Post
Code:
#include <iostream>
#include <cstdlib>
#include <ctime>

int main() {
  std::srand(std::time(0));
  
  float offset = static_cast<float>(std::rand() % 6 + 2) / 10;
  std::cout << offset << std::endl;
}
An offset between and including 0.2 and 0.7 is randomly generated. Add/subtract this offset to whatever coordinates you want to randomize.
Thanks a bunch.
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us