top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

Generate random number form 1 - 100 with probability of 1/100.

+6 votes
107 views

Generate random number form 1 - 100 with probability of 1/100.You are not allowed to used rand() function.
Any simple way of achieving above with using any complex implementation of random number generators algorithm.

posted Feb 2, 2014 by Atiqur Rahman

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
Simple method is to take the system time and mod it with 100 which will give you number from 0-99 with 1/100 probability each as you want 1-100 not 0-99 so just add 1 which will make it 1-100 with each one as 1/100 probability.

System time is a uniform distribution...
Sir .. i think you are talking about something like
srand(time(NULL));
result = (rand()%100)+1;? (which explicitly mentioned not to do so)
if not so will you elaborate little more?
No i have not said to use rand method, my simple algo is -
Step1: Take the unix time say T
Step 2: r = (T mod 100) + 1

Thats it...
Well the other way to achieve this. True.!!!....is there any algorithm to do so??
I didn't get???
Sir... I am asking for algorithm, without using time, if it is possible??
There is no such thing called pure random so the best way is to use time method. However internet is flooded with many algos check these -
http://www.gnu.org/software/gsl/manual/html_node/Random-number-generator-algorithms.html

Similar Questions
+5 votes

1st Example : 18 prime factors are 2*3*3 and it returns count =2 as prime factors includes 2 and 3 only or 2nd example: 27 =3*3*3 and return count =1.

+2 votes

convert a number m to n with minimum operations. The operations allowed were -1 and *2.

For Eg : 4 and 6. Answer is 2.
1st operation : -1 -> 4-1 = 3.
2nd operation : * -> 3 * 2 =6.

+1 vote

Given an array of denominations and array Count , find minimum number of coins required to form sum S.

for example:

  coins[]={1,2,3};
  count[]={1,1,3};

i.e we have 1 coin of Rs 1 , 1 coin of Rs 2 , 3 coins of Rs 3.

Now if we input S = 6 then output should be 2 with possible combination : 3+3 = 6

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...