Timeline for Is this code an efficient implementation of Reservoir Sampling?
Current License: CC BY-SA 3.0
9 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Oct 4, 2012 at 9:29 | comment | added | cl-r |
@Pureferret - Exact, as I usually use .nextInt() so my response out of scope. Corrected
|
|
Oct 4, 2012 at 9:26 | history | edited | cl-r | CC BY-SA 3.0 |
deleted 865 characters in body
|
Oct 4, 2012 at 8:48 | comment | added | AncientSwordRage |
From the docsnextInt(int n): Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence. So no. It can't return a negative.
|
|
Oct 4, 2012 at 8:33 | history | edited | cl-r | CC BY-SA 3.0 |
added 334 characters in body
|
Oct 4, 2012 at 8:30 | comment | added | cl-r |
@Pureferret java.util.Random return also negative number so you cannot test the two limits in the if( ..) statement . Maodify with EDIT
|
|
Oct 4, 2012 at 8:02 | comment | added | AncientSwordRage |
Well the only thing not inside both the else and the if statement is the while and the random number, which the iff relies on - why not make them the same line? Also, I should never get a random number less than 0....
|
|
Oct 4, 2012 at 7:54 | comment | added | cl-r |
@Pureferret else if whithout a final else block do not catch all conditions. But it is that you want. So remove while(1) .. line and break line with a } so you remove the negative int randomised and avoid a Exception (no negative integer in an array position)
|
|
Oct 4, 2012 at 7:46 | comment | added | AncientSwordRage |
So use sc.nextLine() not Scanner(...).useDelimeter("\n")? Got it. Also, I don't follow how an else if would miss some lines? Reservoir sampling takes the first n lines then randomly swaps them out. Sometimes it swaps, sometimes it doesn't I thnk I see what you're doing, but that's not quite the point of reservoir sampling I don't think.
|
|
Oct 4, 2012 at 7:35 | history | answered | cl-r | CC BY-SA 3.0 |