D
D
Dmitry2015-03-01 01:00:37
Programming
Dmitry, 2015-03-01 01:00:37

How to make a random number not random?

It is necessary that, upon request, it gives out a random number, but 20% by 80%.
For example, from a segment from 0 to 10, out of 100 calls, 20% will fall out 0-3, and 80% will fall out 4-10.
I'm not asking for a ready-made function, but maybe someone knows an algorithm for such a random number? Or an example in any language, I myself will rewrite it in python.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Martyanov, 2015-03-01
@trec

The first call to rand shows what "percentage" the next number falls into, and then rand twitches a second time with the necessary boundaries to get the number itself, and the boundaries depend on the first one.
Regarding randomness-non-randomness, rand in your case probably does not produce a random (!!!) sequence.

D
Dmitry, 2015-03-01
@trec

As suggested by vilgeforce , did the following:

from random import randint
def rrand(n):
  if randint(0,9) < n:
    return randint(0,1)
  return randint(2,9)

n - is responsible for the % ratio, in this case it is 2, that is, 20% ( 0.9

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question