Click here to Skip to main content
15,912,578 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: How to gray out PropertyPage Tabs? Pin
Carlos Antollini17-Sep-01 9:48
Carlos Antollini17-Sep-01 9:48 
GeneralRe: How to gray out PropertyPage Tabs? Pin
Jerry Wang17-Sep-01 10:07
Jerry Wang17-Sep-01 10:07 
GeneralRe: How to gray out PropertyPage Tabs? Pin
Not Active17-Sep-01 13:15
mentorNot Active17-Sep-01 13:15 
AnswerRe: How to gray out PropertyPage Tabs? Pin
Not Active17-Sep-01 9:33
mentorNot Active17-Sep-01 9:33 
GeneralSAX and encoding Pin
CodeGuy17-Sep-01 8:45
CodeGuy17-Sep-01 8:45 
Generalconvert Pin
17-Sep-01 8:43
suss17-Sep-01 8:43 
GeneralRe: convert Pin
Chris Losinger17-Sep-01 8:52
professionalChris Losinger17-Sep-01 8:52 
QuestionBest way to get a random integer between 0 and X? Pin
Sprudling17-Sep-01 8:27
Sprudling17-Sep-01 8:27 
I have noticed that many people use (rand() % X) to get an integer between 0 and X. I suspected that this actually would return some numbers more often than others. I ran some checks and I found out it worked as I suspected. For example...

	const largeNumber = 10000000;

	int count[30000]; // To count how many times each number is selected randomly
	for (int i = 0; i < RAND_MAX; i++)
	{
		count[i] = 0; // Set all counters to 0
	}

	int number = 0;
	for (i = 0; i < largeNumber; i++)
	{
		number = rand() % 30000; // Get a random integer between 0 and 30000
		count[number]++; // Increment the counter
	}

	// Find the average numbers of counts from 0 to 2767
	float avgLow = float(count[0]);
	for (i = 1; i < RAND_MAX - 30000; i++)
	{
		avgLow = (avgLow + count[i]) / 2;
	}

	// Find the average numbers of counts from 2768 to 30000
	float avgHigh = float(count[++i]);
	for (i++; i < 30000; i++)
	{
		avgHigh = (avgHigh + count[i]) / 2;
	}

	cout << "Avg: 0 - 2767: " << avgLow << endl;
	cout << "Avg: 2768 - 30000: " << avgHigh << endl;


// This is the result
//Avg: 0 - 2767: 601.948
//Avg: 2768 - 30000: 295.8


As you can see, all the numbers under (RAND_MAX - 30000) has been returned twice as often by (rand() % 30000). I wonder if there is a better (and fast) way go get a random integer between 0 and X?
AnswerRe: Best way to get a random integer between 0 and X? Pin
CodeGuy17-Sep-01 8:39
CodeGuy17-Sep-01 8:39 
GeneralRPC Server not available (cross post) Pin
Bill Wilson17-Sep-01 8:20
Bill Wilson17-Sep-01 8:20 
GeneralCreate[10] Pin
84r17-Sep-01 7:03
84r17-Sep-01 7:03 
GeneralRe: Create[10] Pin
Carlos Antollini17-Sep-01 7:34
Carlos Antollini17-Sep-01 7:34 
GeneralRe: Create[10] Pin
84r17-Sep-01 7:58
84r17-Sep-01 7:58 
GeneralRe: Create[10] Pin
Carlos Antollini18-Sep-01 5:17
Carlos Antollini18-Sep-01 5:17 
GeneralRe: Create[10] Pin
Christian Graus17-Sep-01 12:56
protectorChristian Graus17-Sep-01 12:56 
GeneralHelp with Help Pin
otvac17-Sep-01 6:28
otvac17-Sep-01 6:28 
GeneralArabic in Edit Box....Multi-language Pin
17-Sep-01 6:00
suss17-Sep-01 6:00 
GeneralRe: Arabic in Edit Box....Multi-language Pin
Carlos Antollini17-Sep-01 6:49
Carlos Antollini17-Sep-01 6:49 
GeneralCreate Question Pin
17-Sep-01 5:45
suss17-Sep-01 5:45 
GeneralRe: Create Question Pin
17-Sep-01 5:58
suss17-Sep-01 5:58 
GeneralRe: Create Question Pin
17-Sep-01 6:05
suss17-Sep-01 6:05 
GeneralRe: Create Question Pin
Oscar Vazquez17-Sep-01 8:22
Oscar Vazquez17-Sep-01 8:22 
GeneralButtons with symbol character labels Pin
ChrisP17-Sep-01 5:23
ChrisP17-Sep-01 5:23 
GeneralRe: Buttons with symbol character labels Pin
Joaquín M López Muñoz17-Sep-01 6:39
Joaquín M López Muñoz17-Sep-01 6:39 
GeneralStatic object in mfc, only one instance for all instance of my class Pin
Remi Morin17-Sep-01 4:44
Remi Morin17-Sep-01 4:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.