Jump to content

  • Log In with Google      Sign In   
  • Create Account

fastcall22

Member Since 04 Feb 2008
Offline Last Active Today, 12:42 PM

Posts I've Made

In Topic: Trafic And Activity To The Forums Are Lower?

23 July 2016 - 06:05 PM

Should we have a banner up top saying where the chat’s been moved to?

In Topic: Opengl:why Glcolor4Fv() Does Not Change Color?

21 July 2016 - 07:46 AM

I could be wrong, but usually the vertex attributes are set after starting a drawing command, try this:
glBegin(GL_QUADS); // draw the foreground color box
glColor4fv( c );
glVertex2i(l, b);
glVertex2i(r, b);
glVertex2i(r, t);
glVertex2i(l, t);
glEnd();
Also, inb4 OpenGL 1.1 nonsense.

In Topic: Why didn't somebody tell me?

20 July 2016 - 01:18 PM

If your folder or file is name "StuffAndThings", with out having to click and use the search bar, just start typing "StuffAndThings" (like hitting the key for the first letter of the file to seek to all "s" files) and explorer will eventually land on and highlight the folder or file for you =). This is useful if their are 50 things that start with "S".


Except if the thing you're looking for is first in the list. If you have two folders that begin with the same letter listed first, say "bin" and "bin86", then pressing "b" will select "bin86" first, before "bin". For example, my root drive typically looks like this:

D:\bin → "Program Files"
D:\bin86 → "Program Files (x86)"
D:\home
D:\mount
D:\sdk
D:\tmp
D:\var
And so, if i want to go to "D:\bin\python\35": winkey+E, D:, enter, b, b, enter, python, ...

In Topic: Getting an error while running this program

03 July 2016 - 09:39 PM

It seems the code was written for an older version of Python. Starting with Python 3.0, print changed from a statement to a function. See: What’s New In Python 3.0.

If you are learning Python, then you may consider downgrading to an older version of python.
If you need different versions of python installed side-by-side, then you may consider using a virtual environment.

In Topic: Spreading value x randomly between x amount of elements

27 June 2016 - 02:23 PM

Here’s my approach: http://ideone.com/PBEL1x

While determining the portion, the fractional component is carried over to the next bin.
 
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <cmath>
#include <array>
#include <iterator>


int main(int, char*[]){
	using namespace std;
	srand(time(0));

	// setup bins
	int total = 5000;
	const int MAX_BINS = 25;
	array<int,MAX_BINS> bins;

	// determine weighted distribution
	array<float,MAX_BINS> weights;
	generate(weights.begin(), weights.end(), [](){
		return rand()*1.f/RAND_MAX;
	});
	float weight_sum = accumulate(weights.begin(), weights.end(), 0.f);

	// determine portions
	// use "extra" as an accumulator to determine when to add an extra 1 to the bin
	float extra = 0;
	int used = 0;
	for ( int idx = 0; idx < MAX_BINS; ++idx ) {
		float actual = weights[idx]/weight_sum * total + extra;
		int count = (int)actual;

		extra = fmodf(actual, 1.f);
		bins[idx] = count;
		used += count;
	}

	// any accumulation error is added to the first bin
	int error = error;
	bins[0] += total - used;

	// output results
	cout << "total:\t" << total
		<< "\nbins:\t";

	copy(bins.begin(), bins.end(), ostream_iterator<int>(cout, "\t"));
	cout << "\nerror:" << error
		<< "\nextra:" << total - accumulate(bins.begin(),bins.end(),0) << '\n';
}
Output:
total:	5000
bins:	119	24	253	186	176	121	283	85	332	51	350	34	304	7	50	371	338	52	333	363	280	372	92	140	284	
error:	0
extra:	0
And is flexible where there isn’t much to distribute:
total:	3
bins:	0	0	0	1	0	1	0	0	0	1	
error:	0
extra:	0
EDIT:
Actually, I just realized that this isn’t the best approach for small numbers over numerous bins, as the accumulator will favor bins toward the end.

PARTNERS