last day (15 days later) » 

3:51 PM
I have to say, I am a little curious on something:
@AustinFrench - no, because it will shift all values — Erno de Weerd 2 mins ago
If you have a range of 1-1000 minus the range 2-300 and you want a uniform distribution...
Can you really call it uniform if all numbers are randomly generated in the 2-300 rage are shifted right?
You will still have number 1-199 generated randomly, no numbers 200 - 300, numbers 300-400 will show bias, correct? and then normal distribution 401-1000?
 
4:06 PM
correct. So it is better to shift them all
as I did in my answser
So if you generate between 0 and 900 and shift any number higher than 200, 100 up. it should be ok again
 
You did if greater than 200 {Shift}
 
yes but did not generate 900 - 1000
 
Would it not make as much since to shift any number less than 300?
*sense
sorry
 
sure as long as you discard the numbers lower than 0
or generate between 100 and 1000
so you don't have to discard
 
Actually, I guess that creates another problem, because then 151 would fall into the bad range.
 
4:12 PM
no just move any number less than 300, 100 down. If you do not generate numbers between 0 and 100 there is no problem
151 would become 51
 
OK, So I think I get what you are doing...
 
Create a gap at either end and shift to the gap
 
So really we need a buffer range on the head and tail end of the distribution and possibly signed ints if our native range does go to 0 on the low end?
Instead of discarding 70 because it would be reduced to -30?
Or is discarding some OK?
 
70 would not be generated. Just generate between 100 and 1000
and shift any number lower than 300
100 down
 
Gotcha... And leave anything above 300 alone.

Finally clicks right
 
4:17 PM
yes
:)
 
OK, so from a Comp Sci perspective...
What is wrong Poomrokc (sp?) approach:

Random rand=new Random();
int value= rand.next(0,600);
while(value>=200 && value<=300)
{
value=rand.next(0,600);
}
Simply that we are discarding the numbers?
 
It might take a long time
so it is wasteful
it might take for ever
unlikely
but unpredictable
 
But wasteful would be OK if it created a better result or more uniform distribution if that was the primary concern, no?
 
it is not a better result. It just takes more time
so it is not wrong from a distribution point of view
but it is when trying to be efficient and predictable
 
Yes, I understand that much. But for the sake of being wasteful it is wasteful because it does not produce a better result. That it is not wrong makes it an OK model just not ideal?

Also, Having though on it, we know random in .NET is not really random, so discarding any numbers completely seems like it ruins or distribution curve. ?
*our curve
On discarding samples for example, if for some reason Rand.Next was generating a ton of 250s but we throw them all away and get new numbers instead of shifting them right, we would not see the anomaly.
 
4:28 PM
Nothing is random. It's not just .NET. discarding is not bad from a distribution point of view, it is just bad by wasting time. It is an interesting question what it would mean if there was along range of 250s. It would make me doubt the algorithm. But the client can't fix that by throwing it away because the generator doesn't know we are throwing them away
 
Agreed, and straying off the topic of initial problem: But wouldn't we want to know of that problem if there was a problem in the algorithm, bad seed for example... In security a very unbalanced distribution model for things like random hashes in password hashes could be a vulnerability... ?
 
Yes, and that is why random algorithms are so very difficult to get right. We would want to know but i don't think we should try and compensate in our day-to-day code.
 
So: In summary neither approach produces less viable data: But one is potentially many times more efficient.
 
yes, although a lot depends on your definition of "many times more" :)
 
LOL, going with the almost impossible but earlier mentioned "never gets unstuck"
 
4:38 PM
:)
 
Thanks a lot for joining me here too, ironed out some confusions I had on some of the comments and answers...

I'd like to condense this into and answer/ wiki...
 
In my work I need to write very fast code, we care less about memory (that can be bought) but a lot about time (can't be bought) So I tend to be focused on speed :)
no problem, You might poke around and find a better fitting question (on random distribution) this question is very low quality and probably not worth the attention
 
Makes perfect sense. My thought process gravitates towards accuracy so any bad data seems not optimal to me, and you solution seems better for that too
Good point.
An old question might not get the attention either though
But at least it would be there
 
yes, and if it is a good question it will be found
 

last day (15 days later) »