« first day (786 days earlier)      last day (4161 days later) » 

8:02 PM
@Xeo Actually, there's no way the standard can require that with custom hashes. Forget it.
 
@R.MartinhoFernandes right
@R.MartinhoFernandes you could generate a hash-hasher from teh custom hash I suppose
 
@R.MartinhoFernandes I'm surprised it wouldn't say something like requires O(1) with a 'good' hash function
 
@Collin Define 'good' <--- The problem here.
 
@Collin even a good hash function can hit that worst case sometimes
 
no it wasn't that one
 
8:10 PM
@ThePhD Yeah, but you can be fantastical about it and say "generates no collisions for a given set"
 
Xeo
Y'know, sometimes, it ain't bad to be the PC expert around here. Getting 30€ for 40mins of "work" (haha) is nice.
 
So, 'perfect' hash function
unless average case is binding in some way
 
Xeo
Anyways, @DeadMG, how did you come to that conclusion earlier, that operator precedence changes between UDT and fundamental types?
 
@Collin "perfect" hash function has a specific definition.
 
8:11 PM
What am I doing wrong, crashes at line 10.
 
@MooingDuck I knew that sounded familiar as i was typing it
 
2 hours ago, by R. Martinho Fernandes
@Zoidberg'-- Not for fundamental types.
implies that fundamentals are RTL and UDTs are LTR
 
Xeo
@Nils You want to copy the memo cache.
 
no I don't :)
or not sure I thought [&] captures by ref
 
Xeo
Yes you do, otherwise it's out of scope when you call the lambda.
 
8:13 PM
@Nils why not just use an array? Much faster and less memory.
 
@MooingDuck insertion?
 
Xeo
@Nils Yeah, [&] captures by ref a local variable.
If you leave the function scope, that local variable is dead.
 
@Nils why would you be inserting in the middle for fibonacci?
 
@frankc Read the question: "c++ how to get a random number to be zero" Then read my answer. My answer answers the question. The only snarky one I see is you. — Neal 31 secs ago
:-(
 
@Xeo and where do I leave this? The lambda is defined inside my function..
 
8:14 PM
@Xeo I think I'd suggest static local actually
 
Some people just do not understand how Stack Overflow works...
Sorry for the intrusion...
 
@MooingDuck Well array/std::vector would be an option I agree.
 
Xeo
@MooingDuck Yeah, that'd be better for true caching.
 
@Xeo So in this case [&] captures the locals from main() ?
 
@Neal I agree with him, your answer is clearly not helpful to the intent
 
8:16 PM
@Neal Well played
 
Xeo
@Nils What? No, it captures the local variables inside your fibonacci lambda.
And then you return that lambda, and the local variables are out of scope.
 
@MooingDuck the OP never asked why he never got Zero. he just doent understand what random means! if you want to get zero every time, then just set the variable to zero!
 
@xeo ah I see and what might be a solution for that?
 
I am not sure what the issue is...
 
Xeo
static local or by-value capture...
 
8:18 PM
> However I have noticed that it NEVER picks '0' for what I need to do it can't be BETWEEN 0 and 8 it has to be FROM 0 to 8. If you can give me any help on this I will really appreciate it.
@Neal What?
 
@Neal you only read teh title and are ignoring the context provided by the question entirely. The OP seems wants to know why his RNG never produces zero, not how to make it always produce zero.
 
@Xeo ok static added, now crashes at 14
 
I said that because for fundamental types it's irrelevant, because addition is associative, and the standard allows evaluation in any order.
 
@SomeKittens I have. The OP did not understand why a Random number what not falling on zero most of the time. So in order for a "random" number to be zero all of the time then you need to set it to zero! Yes the randomness is gone, but that is what the OP wanted! — Neal 1 min ago
 
8:20 PM
maybe using a struct would be better
 
@Neal That's not at all what the OP said
 
well I even lowered the range from 8 to 2 and had it print every result it got after about 20 results of 1 and no 0 so I figured something was wrong. — Ian Lundberg 35 mins ago
 
@Neal "The OP did not understand why a Random number what not falling on zero most of the time" FALSE. He said "I have noticed that it NEVER picks '0'". That's very different than your interpretation.
 
@Collin > However I have noticed that it NEVER picks '0' for what I need to do it can't be BETWEEN 0 and 8 it has to be FROM 0 to 8. If you can give me any help on this I will really appreciate it.
That is a direct quote
@MooingDuck I will update my answer.... one sec
 
"it has to be FROM 0 to 8"
 
8:22 PM
@Neal Yeah, and where in there did you manage to read that it always needed to be zero?
 
@Neal he wants inclusive bounds, not exclusive bounds. (which it currently is)
 
user1182183
namespace in namespace in namespace, good or bad programming habbit?
 
-3
A: c++ how to get a random number to be zero

NealIf you want to get zero all of the time you can do this: Random_Number = 0; // it is now ZERO but in the case where you want to get zero some of the time you cannot rely on a random number! It might not ever fall out to be on zero, no matter how small the margin is.

New version of my answer ^
 
@Neal He never said most of the time either. What question are you reading?
 
@Neal that... but... no!
 
8:23 PM
I enjoy your effort.
 
@Neal You really look like you're trolling. Are you trolling?
 
It isn't obvious?
 
@Collin read the last part to my answer. even if he wants it to be zero "some" of the time, you cannot rely on a random number!
@MooingDuck I really am not trying to... but it sure looks like it I guess...
 
I gave you a +1 because I can
 
Meh this is a lot harder than in Python / JavaScript..
 
8:26 PM
 
@Neal actually, rereading the question, I also made assumptions about the OP's intent. I've removed my downvote from your answer, because the question is stupid.
 
@Neal He ran his code a bunch of times and saw a lot of other numbers than 0, but he wants that included, it's reasonable to assume it's going to come up about 1/10th of the time, so if he runs is 30 times and sees no 0s, that's why he's confused
 
user142019
Is there something like std::istream >> ignore_this?
 
@Zoidberg'-- of what type?
 
user142019
@MooingDuck string
 
8:26 PM
Seriously has anybody an idea how to memoize Fibonacci w/o classes or templates?
 
@Zoidberg'-- std::string ignore_this?
 
well I even lowered the range from 8 to 2 and had it print every result it got after about 20 results of 1 and no 0 so I figured something was wrong. — Ian Lundberg 41 mins ago
 
user142019
I want to ignore one formatted input.
 
std::string ignored;
std::cin >> ignored;
 
@MooingDuck thank you! the OP was expecting zero when it is possible that zero wont show up! It is like if I roll a die 6 times and no five comes up....
 
8:27 PM
@Nils yeah, a static vector
 
@MooingDuck I have no idea what he's trying to say there
 
ok also w/o a static vector
:P
 
@Collin "I'm retarded, I don't know how random numbers work so I'm blaming the language"
 
because the fib function itself also goes out of scope!!
 
Has anybody an idea how to solve a problem without using a solution?
 
8:27 PM
Ooohh he did rand() % 1
 
get somebody else to solve it
 
@Collin he seems to claim he changed it to Random_Number = rand() % 2 and got 20 1s in a row.
 
@R.MartinhoFernandes I am not so sure if there is none..
 
@Collin I think he did rand() % 2
 
@Nils There are several. You were given several already.
 
8:28 PM
shared_ptr will safe me
 
@Nils that's why a static vector.
@Nils wtf
 
@MooingDuck I think it's reasonable to assume you have something wrong at that point
 
Not really
 
Assuming he means he didn't see any 0s
 
Just means you're unlucky
 
8:29 PM
@Collin that's what I believe he claims. I make no statements about what he actually did.
 
@Rapptz Lets see if I can remember my probability, what's that, (1/2)^20 chance of getting 20 1s in a row?
 
@Collin yes
 
I think he said "I didn't get any zeroes" not "only 1s"
scratch that
 
9.53674316e-9% chance of it?
 
@Rapptz in the comment he says he got only ones
@Collin yes
 
8:31 PM
No implication of 20 1s in a row just says "after about 20 1s"
Honestly OP's retarded, why do I care
 
@Rapptz agreed in every way
 
user142019
What happened to Ideone. ideone.com/IyfPYE
 
user142019
> 'nullptr' was not declared in this scope
 
GCC 4.5 has no nullptr.
 
user142019
lol
 
8:32 PM
Why don't you use LWS or Coliru?
 
@frankc it was not meant to be an insult. I am done with this answer. Move on. — Neal 6 secs ago
 
user142019
@Rapptz They didn’t give the same output as my machine.
 
Hmm. It appears that in Germany, any game with a 18+ rating has to be sold at night.
 
user142019
It’s probably different on Linux.
 
user142019
I need this for my new web app.
 
8:35 PM
0
Q: How can we scan a 100 bytes from STDIN in one go in C++

sharkyThe scanner waits till we enter 100 bytes of data. So if we are redirecting a file into the executable's input, if the file has > 100 bytes of data. I scan it at one go, rather than line by line with fgets() or scanf("%s") etc.

@MooingDuck: why the retag from to ? o.O
 
That guy has another question
0
Q: c++ count amount of numbers in char array?

Ian LundbergI have a char array that has number 0-8 in it in char form Board[0] = '0'; Board[1] = '1'; Board[2] = '2'; Board[3] = '3'; Board[4] = '4'; Board[5] = '5'; Board[6] = '6'; Board[7] = '7'; Board[8] = '8'; and some of them are changed to either an 'x' or an 'o' based on user input however I need...

 
user142019
length . filter isDigit
 
How does for each(....) work for him?
 
that exists?
 
user142019
8:37 PM
#define each
#define in :
2
 
user142019
:P
 
It's a MS extension.
 
Ah.. never used it.
 
Isn't isdigit that silly function that UBs to the point of being worthless?
 
do you mean ::toupper
 
8:39 PM
Ah.
Was confused.
 
@Zoidberg'-- Hahahaha xD
 
user142019
Is it really that funny?
 
Yes :P
 
so they didn't fix the toupper thing in C++11?
 
I'm tired, you made me laugh, you got a star. Life goes on.
 
8:41 PM
well
if you're lucky, then in C++14 Unicode support will be added
 
user142019
@Rapptz it’s from the C library. They cannot just change that.
 
They also did not fix header files..
 
as specified by yours truky
 
I am certainly doing things wrong here, but somehow this must work with shared_ptr..
 
user142019
Stupid PHP room.
 
user142019
8:48 PM
@Nils don’t compile C++ code as C.
 
user142019
codepad doesn’t support C++11 and std::function.
 
Yes I know, hopefully your compiler does :)
 
user142019
 
user1182183
hm if I have a list of adresses then I can just make then const int?
int HudMode = 0xBA6769;
*HudMode = false;
 
user142019
@GamErix you cannot dereference an int, silly.
 
user1182183
@Zoidberg'-- isn't *(address)= set value at adress?
 
user142019
@StackedCrooked you shouldn’t escape tabs. :P stacked-crooked.com/view?id=b1d39232f7ddfab1150c2e759de5403a
 
Could it be that fibPtr goes out of scope?
 
user142019
@GamErix does that matter? You cannot dereference an int.
 
user142019
8:51 PM
HudMode is an int.
 
user142019
You cannot dereference that.
 
user142019
You can dereference pointers, not integers.
 
user1182183
then how do I set someting_at_address to false?
 
@Zoidberg'-- That looks wrong indeed.
 
8:52 PM
@GamErix You are given a pointer to it. WTF are you trying to do.
You are XYing.
 
user1182183
 
user1182183
for example I want to set players money to 10000
 
user142019
oh
 
user1182183
int Money = 0xB7CE50;//DWORD
*Money = 10000; ?
 
user142019
Cast the address to a pointer and dereference that pointer.
 
8:54 PM
Those are addresses in gta_sa.exe's address space.
 
user142019
@GamErix YOU CANNOT DEREFERENCE AN int
 
You cannot use them directly from your address space.
 
user1182183
int * ptr = (int*)money;
ptr = 5; ?
 
user1182183
and why couldnt I use those adresses in a DLL?
 
user1182183
they're static
 
user142019
8:55 PM
That might work. I don’t know what the exact conversion rules are.
 
@GamErix See, if I have no idea what you are trying to do, why do you assume I do?
 
So what you guys are probably better with C++ than I..
 
user1182183
@R.MartinhoFernandes if I attach Cheat Engine (debugger, allows you to scan memory and edit adresses) and supply the address "0xB7CE50" then I can edit that value... and it doesn't change with each application start ;o
 
user142019
RT @_d3f: http://i.imgur.com/Ost52.png > Women > Coding
 
user142019
epic fail
 
8:59 PM
that's almost a bit mean
 
lolwut, that's just lousy HTML with inline styles.
 
user1182183
xD
 
user142019
That code will never validate.
 
user142019
<table><table>
 
And no <head>
 
9:00 PM
@R.MartinhoFernandes Can you tell me why my code crashes?
 
user142019
<h1><p class='sansserif'>Title</h1> would have been valid if you could have used <p> in <h1> :P
 
@Nils Sorry I haven't been paying attention. Can you link me to it?
 
user142019
<p>
    foo
    <ul></ul>
</p>
<!-- is parsed as: -->
<p>foo</p>
<ul></ul>
 
user142019
I hate HTML.
 
@R.MartinhoFernandes codepad.org/Xu87qF7M
 
user142019
9:02 PM
hate-tml
6
 
@Zoidberg'-- In soviet russia, HTML hates you.
 
ecchi tml
 
Xeo
@StackedCrooked heh
 
user142019
What is ecchi.
 
Xeo
H
 
user142019
9:03 PM
Oh. Porn.
 
Xeo
Very descriptive, I know.
 
fib_func_ptr fibPtr = std::make_shared<fib_func>([memoPtr, fibPtr]
 
Is the Japanese pronunciation of the letter H.
 
user142019
HENTAI
 
This passes fibPtr by value before it it initialized.
 
Xeo
9:03 PM
And at the same time the word for "perverted stuff"
Well, actually "ecchi" is more like "lewd", right? And "hentai" is "perverted"
 
user142019
There are 1000000 different kinds of manga. I can’t remember all those names.
 
Xeo
Also, there are so-called "hentaigana", which are old variants of modern hiragana.
 
@Zoidberg'-- I think you'll remember ecchi.
 
@R.MartinhoFernandes I don't quite understand what does not get initialized?
 
Xeo
fibPtr before you value capture it.
 
9:05 PM
@Nils fibPtr. You cannot capture it by value in its own initialization.
 
ah no recursive lambdas then?
 
Nope.
 
Xeo
Not without std::function. :(
and even then only with ref-capture.
 
NOOOOOOOO now I cry!!
:)
 
You can (ab)use indirection, but that won't work with the lifetime guarantees you want.
Next up: fixed point combinators.
 
user142019
9:07 PM
template<class F>
auto fix(F const& f) -> decltype(f(f)) {
    return f(f);
}
 
let x = f x in x -- ain't this pretty?
 
Xeo
I think I still don't understand what those are useful for.
 
@Xeo ahem.. so I could declare a shared_ptr to std::function somewhere and then assign a lambda to it which calls it again?
 
user142019
std::function<void()> foo;
foo = [] { foo(); }
 
Xeo
@Zoidberg'-- No.
 
9:09 PM
Fail.
 
user142019
Oh. lol
 
Xeo
@Nils I think that works, but I wouldn't want to go that route.
Since it'll never clean itself up unless you .reset inside the lambda.
 
@Nils Once you return from fibonacci, that std::shared_ptr will be dead.
 
Not if you new it!
 
Xeo
You might go with unique_ptr and a simple value capture of what .get() returns.
 
9:10 PM
Please don't shoot me.
 
Xeo
@LucDanton Not if you copy-capture it :D
 
@LucDanton The share_ptr to the lambda, but we return a copy of it
 
@Xeo But then you take a copy of an empty pointer :| Stop confusing people please.
 
user142019
Solution: don’t use C++.
 
Xeo
@LucDanton No, make it point to an empty std::function, copy capture the shared_ptr and assign to the pointed-to std::function. Atleast I think that works.
 
9:12 PM
 
I was reading JS the good parts and just wondering how close I could get to this with C++11. codepad.org/8e8sR29R
 
a massive dildo
 
Xeo
@Nils Garbage-collection helps immensely with stuff like this.
 
I can see that now.
 
user142019
9:13 PM
@TonyTheLion great out-of-context star.
 
Ha! Next interview when somebody asks me what do you need GC for :)
 
Xeo
Tony the H-Lion
 
@Xeo Recursion in a package.
 
@TonyTheLion Boats always have the weirdest boners.
 
9:14 PM
Yea
those horny mofo's
 
You can write a fixed point combinator that memoizes, and then reuse it to memoize existing functions.
 
@Nils what is "JS the good parts"
 
@Cheersandhth.-Alf A book.
 
A book, just google it.
 
Xeo
9:16 PM
Gnaaah, why can't I start my debian vbox again.
 
user142019
 
the function in javascript is a stand-in for a class in C++
 
With that the only problem is that fibPtr is out of scope when returned I think..
 
9:18 PM
because (old) javascript is based on exemplars, just creating new object like existing ones
 
user142019
If you want classes in JavaScript use CoffeeScript.
 
user142019
But I love prototypes and duck typing.
 
so shared_ptr goes out of scope when returning.. but what about unique_ptr
 
Xeo
All local variables go out of scope when returning, d'uh.
 
> Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart.
The CoffeeScript guys are obviously comedians.
 
9:21 PM
yeah but it returns also a copy of the shared_ptr so how is it clear that the usage_count goes to zero?
 
user142019
lol
 
user142019
I like JavaScript’s object model.
 
user142019
Its type system not so much, but its object model is great.
 
user142019
But {} + [] === 0 is just ridiculous.
 
Can I wrap an std::function inside unique_ptr if so how?
 
user142019
9:22 PM
{} + {} being NaN is actually true. :P
 
Xeo
Was that a cue for wat?
 
user142019
wat
 
user142019
I don’t know why but I feel like in JavaScript I can get things done much more easily than in other language.
 
@Xeo This talk was a work of art.
 
@Zoidberg'-- It's also not true.
Seriously, if you want to diss stuff, at least get your facts straight.
 
user142019
9:26 PM
It depends on the implementation.
 
How do I call the () operator inside of itself?
 
user142019
In V8 it’s an object and in Safari it’s 0.
 
@Nils operator() in C++
 
9:29 PM
this at least works
 
^ The spirit of the JS code translated to C++.
 
yeah :)
 
@Nils why are you still using an unordered map for Fibonacci?
 
bah
because I didn't care
 
@Nils though I do approve of a class over a static local
 
9:32 PM
sure
 
 
@Cheersandhth.-Alf That's pretty good, other than I'd throw in a reserve as well
 
@MooingDuck ^ :-D
 
I have just rolled a die and got 14.
 
user1182183
aand answered lol xd
 
9:33 PM
14 is more random than 4.
 
@MooingDuck premature optimization :-) (oh well can't make that argument with memoization in the picture, but)
 
user1182183
I <3 SO
 
user1182183
if I could I would marry StackOverflow
 
@R.MartinhoFernandes as is zero
 
user1182183
will domain marriages be possible in the future? gay and lesbian marriages are allowed xD
 
9:34 PM
So now a generic memoizer for all kind of functions :)
 
@Neal None of my many dice have zeros.
 
@R.MartinhoFernandes idk what type of dice you have been using...
:-P
 
@R.MartinhoFernandes pft, I have dice with zeros
 
With variadic templates I could might build a memoizer for almost any kind of std::function.
But I really need to get some sleep now :(
 
@R.MartinhoFernandes I have a haunted mansion board game with d6s where the sides are 0,0,1,1,2,2, which is nice, because rolling 3 means a range of 0-6 with an average of 3. All the stats are easy to calculate.
 
9:39 PM
Actually, my d10s have zeros inscribed, but those are tens not zeros.
 
@R.MartinhoFernandes YOU LIED TO ME
 
user1182183
trolollololololol *(int*)Address::Ped::Money += 1; works ;D
 
I'm off, thx for the help with the lambdas and things!
 
Xeo
@DeadMG: "Firstly, each expression would be fully evaluated in it's own right before evaluating other expressions- that is, the compiler no longer has the right to interleave them" -- wat? How could the compiler interleave evaluation of subexpressions? It can't!
 
subexpressions != function executions
 
9:51 PM
@Xeo f(x() + y(), w() + z())
 
gah! A proposed edit to stackoverflow.com/questions/13809747/… has lots of good fixes in teh text, but screwed up the tags bad. Not sure what to vote. I guess reject...
 
you never read about how f(unique_ptr<T>(new T), unique_ptr<T>(new T)) is unsafe?
 
@MooingDuck Improve?
 
@R.MartinhoFernandes oh yeah
 
it's unsafe because the compiler absolutely has the right to interleave execution of the expressions which are arguments.
 
Xeo
9:52 PM
@DeadMG Oh, so you want function arguments to be evaluated fully before others are evaluated. Maybe you should mention that explicitly.
 
it is mentioned explicitly- the compiler no longer has the right to interleave expressions.
 
Great, they added WarHammer 40k to the THQ bundle. Guess I am gifting someone yet another game this Christmas.
 
user1182183
does DLLMain automatically get called when LoadLibrary is used to load it? Or Do I have to call it myself from the DLL which is issuing LoadLibrary?
 
It's called automatically.
 
Xeo
@DeadMG It's not quite clear why you want it, though. IMO, anyways.
 
9:54 PM
it is called for you
 
user1182183
@DeadMG ah okay ;D
 
@Xeo Because, for one, I don't believe there are any significant optimizations possible, and it leads to significant unsafety and UB in the language which frequently trips up new users.
 
Xeo
@Xeo: we have that: constexprMooing Duck 56 secs ago
@MooingDuck ^ wat?
Oh, I did leave a comment there.
And no, constexpr doesn't suffice.
 
@Xeo no? Why not?
 
Because constexpr does not mean what many people think it means.
It means "this function may be used in constant expressions".
 
Xeo
9:56 PM
And it also doesn't tag functions in a way that is queryable by a user.
 
@R.MartinhoFernandes it can't have side effects, ergo it's a pure function.
 
Xeo
(aka, overload on pureness)
 
@MooingDuck But it can.
 
@R.MartinhoFernandes whatnow?
 
Constant expressions cannot have side effects.
 
9:56 PM
@Xeo that'd be cool
 
constexpr functions can be used in constant expressions, but not exclusively.
They don't have to resolve to constant expressions all the time.
 
Xeo
@MooingDuck That's the whole idea behind pure, making it something like the cv- and ref-qualifiers on member functions.
 
@R.MartinhoFernandes are you claiming constexpr is not pure?
 
@MooingDuck I am claiming it does not imply that, yes.
 
oh wait, member values definintely make a wierd case at least.
 
Xeo
9:58 PM
Only one path inside a constexpr function needs to be pure.
 
@R.MartinhoFernandes ...oh
 
Xeo
and you can use blah(0) in a constant expression.
The others not.
 

« first day (786 days earlier)      last day (4161 days later) »