Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[c++] Randomnize an integer?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Engineer
Expert Cheater
Reputation: 1

Joined: 25 Nov 2007
Posts: 170

PostPosted: Wed Jan 23, 2008 11:09 am    Post subject: [c++] Randomnize an integer? Reply with quote

*insert title here*
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Wed Jan 23, 2008 11:13 am    Post subject: Re: [c++] Randomnize an integer? Reply with quote


_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Wed Jan 23, 2008 11:15 am    Post subject: Reply with quote

Random()
Back to top
View user's profile Send private message
Engineer
Expert Cheater
Reputation: 1

Joined: 25 Nov 2007
Posts: 170

PostPosted: Wed Jan 23, 2008 12:20 pm    Post subject: Re: [c++] Randomnize an integer? Reply with quote

Back to top
View user's profile Send private message
Reak
I post too much
Reputation: 0

Joined: 15 May 2007
Posts: 3496

PostPosted: Wed Jan 23, 2008 12:33 pm    Post subject: Reply with quote

Code:
yourinteger = Rand(1337)

If Random is the same as Rand, then it will your integer to a number betwen 1~1337 or -1337~1337.
Back to top
View user's profile Send private message
Engineer
Expert Cheater
Reputation: 1

Joined: 25 Nov 2007
Posts: 170

PostPosted: Wed Jan 23, 2008 1:00 pm    Post subject: Reply with quote

Code:
error:'random' cannot be used as a function;
error: the address of 'int rand()' will always evaluate as true;
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Jan 23, 2008 1:14 pm    Post subject: Reply with quote

Code:
#include <time.h>
// or #include <ctime>
...
int iRandom = rand() % 10 + 1;

Generates a Number 1 - 10 ( hence the +1, if that wasnt there it would generate 0 - 9 )

where rand() is the function
% MAX_RAND which is the highest array of numbers you want to generate
+ 1 just increases the number by 1 so you can have 1-100 instead of 0-99


Edit: but seriously, i googled this just now and found the first link

http://www.cplusplus.com/reference/clibrary/cstdlib/rand.html

_________________
Back to top
View user's profile Send private message
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Wed Jan 23, 2008 3:58 pm    Post subject: Reply with quote

Generating a random number with a given range:

Say we want to have a range of 15 min - 25 max.
The default would be
Code:

int ran = rand() % 26;


This will give us a range of 0 - 25. We will now shift it.
Code:
int ran = 15 + rand() % 26;

This will give us a range of 15 - 40, but we want it to 25. To fix it, we just subtract it by 15.

Code:
int ran = 15 + rand() % (26 - 15);

This will give use our desired range 15 - 25. With this, you can form an equation to use in a function
Code:

x = min
y = max

x + rand() % ((y + 1 ) - x)


Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Wed Jan 23, 2008 5:29 pm    Post subject: Reply with quote

using killersamurai's code up there, heres a simple function u can use

Code:
int Randomize( int iRandomMin, int iRandomMax )
{
   int iRandNumber = iRandomMin + rand() % ((iRandomMax + 1 ) - iRandomMin);
   return iRandNumber;
}


Example:

Code:
#include <iostream>
using std::cout;
using std::cin;

int Randomize( int iRandomMin, int iRandomMax )
{
   int iRandNumber = iRandomMin + rand() % ((iRandomMax + 1 ) - iRandomMin);
   return iRandNumber;
}

int main()
{
   int iMin, iMax;
   cout << "-- Randomizor --\n" << "\nChoose Mininum Value: ";
   cin >> iMin;
   cout << "\nChoose Maxium Value: ";
   cin >> iMax;
   cout << "Random Number from those numbers: " << Randomize( iMin, iMax ) << "\n";
   cin.sync();
   cin.ignore();
   return 0;
}

_________________
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Thu Jan 24, 2008 8:49 am    Post subject: Re: [c++] Randomnize an integer? Reply with quote

http://www.boost.org/libs/random/
ZzOoZz wrote:
Rand() is the function, but how do i set the int to change?
srand()
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites