bayram's blog

By bayram, 10 years ago, In English

How can I make random generator function.
random(a,b) must return number between a and b with equal probability for all numbers.
Without using any getrandom(), gettime() or similar functions of programming language.
Thanks for helping!

  • Vote: I like it
  • +8
  • Vote: I do not like it

»
10 years ago, # |
Rev. 2   Vote: I like it +8 Vote: I do not like it

Just implement your own random generator. For example Linear Congruential Generator — though of course without any timing function etc you will need to seed it manually. (but it is just the same as with rand and srand functions in C)

There are many implementations so you can easily find samples. Google for "Java Random Source" or something like this if you need them.