Interview Question
Financial Software Developersbetter way is lets have array and repeat number equivalent to the probability you want say for this case array will consists of 0,1,1,2,2,2,2 now we can use this rand function in this way
#define ArrayMax 6 // our index starts from 0
for (int i=0;i<ArrayMax;i++)
{
print ("\t Arr[i*rand()]");
}
this is some sort of the way we can do it
comments are welcome
inverse transformation: 2*sqrt(rand())
- Anonymous June 12, 2009