Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
a slime
Apr 11, 2005

Martman posted:

Hi everyone. I've got an issue with random numbers.

I'm doing a project in which I'm trying to make a bunch of little bacteria or animals or whatever (called Moops) run around a 2-dimensional grid and reproduce. When using C++'s standard random number function, I'm getting some behavior that's very obviously not random. Moops seem to travel in groups and go the same direction for long stretches of time. It's not entirely fixed, but it's just very clearly not random enough for my purposes.

I've tried seeding the random numbers using system time; is there a better way to achieve closer-to-true-randomness?

Boost has a very nice random number library, read more here

Although I agree with the above poster that it is unlikely to be the cause of your problems. Just to cover all the bases- you're only seeding the RNG once, right?

Adbot
ADBOT LOVES YOU

a slime
Apr 11, 2005

You wrote too many comments and overloaded the compiler

a slime
Apr 11, 2005

Is it possible to define member functions of a private nested class as non-inline? How?

a slime
Apr 11, 2005

Why. Whyyyy :bang:

http://codepad.org/Zu1ziyYt

a slime
Apr 11, 2005

Paniolo posted:

Because an array is not a pointer, even if you can use it like one in certain situations.

Can you please elaborate/link me to something because I always assumed buffer in this case would just a pointer to the first element of the array

a slime
Apr 11, 2005

jonjonaug posted:

Read this for information on the relationship between pointers and arrays in C/C++.

Thanks for the link. The More You Know...

a slime
Apr 11, 2005

I have what I feel is a dumb question but I can't figure out a solution to it that I like. Let's say I have a few objects with a common base class. I want to add them to some container I've defined that will have to perform some different actions depending on which derived class is being added.

I wish I could do something like overload some function like:

code:
class Container
{
    ...
    void add_item(DerivedA* item);
    void add_item(DerivedB* item);
    void add_item(DerivedC* item);
};
and have it resolve the function to call at runtime. The only solution I have right now is to move the functionality into the derived classes and do

code:
base_p->add_to_container(container);
but this is just lovely because the functionality just doesn't really fit there. Is there a better way to do this?

a slime
Apr 11, 2005

Thanks!! :doh:

a slime
Apr 11, 2005

rawstorm posted:

Help please.

I googled it and the first result explained literally everything you're asking, have some shame please

a slime
Apr 11, 2005

unpurposed posted:

I'm just getting started with C, so I'm not very well versed in the intricacies of it. Something that's confusing me, but that I was told was correct, is using this uint32_t as a sort of array. It works properly and my code sorts everything right, but I don't know why I can index into this uint32_t like that.

Another dumb C question is: is there a way to get a range of an array by just going array[start, end], or can I just access an array's values individually?

uint32_t just specifies that you want an unsigned 32 bit integer. Your two arguments to sort (left and right) are not uint32_t's, they are pointers to uint32_t's. You can index it as you do because presumably you have elsewhere allocated memory between whatever left and right point to. Also, *(index + 1) is the same as index[1]

When you say you want a range of an array, what exactly do you mean? Do you want to make a copy of the array you already have, containing only a subset of the original values? If not, you can just pass anyone a pointer to array[start], and the length of the range of values you want.

a slime
Apr 11, 2005

fankey posted:

FYI - we are C++ developers in Boulder CO.

do ya'll pay BONKERS money tho

Adbot
ADBOT LOVES YOU

a slime
Apr 11, 2005

giogadi posted:

I always find it sad when we have to give context like “it’s for an assignment” to justify doing something in a weird (or worse) way. Surely if something is worth learning about in school, then there must be some way to apply it that actually makes sense in practice too.

I think all the time about how I’d teach stuff if I were a teacher, but I wonder how much is out of the teachers’ control due to constraints on curriculum, etc

And so on, Sure. I'd tend to agree

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply