0

I need to create a random number without using any library functions or complicated mathematics i.e math.h library.

How do I do this without using a standard library function?

Aroo
  • 55
  • 1
  • 10
  • @walnut: what if that is the kind of "complicated mathematics" OP so desires to avoid? – Jongware Apr 05 '20 at 09:40
  • @usr2564301 OP is saying that they cannot use `math.h`: "*i.e. `math.h` library*", not "*e.g. `math.h` library*" and if that was to count as "complicated mathematics", then there will surely be no way of implementing a pseudo-random number generator without it. – walnut Apr 05 '20 at 09:42
  • Like using of power functions or sine functions and others which can just be imported and not coded right now. I want to fully code it with only `stdio.h` and nothing else – Aroo Apr 05 '20 at 09:43
  • For something like a game where the program is taking user input, so its execution time is focused round that, one simple way is to use the value from `clock()` and add that to the value from `time()` at program startup. It should be impossible for the user to fudge it. to Of course, you'll probably need a modulus to range it. – Weather Vane Apr 05 '20 at 09:44
  • Yes. I am new to c and I know only python before hand.. Yeah I actually meant rand() and not random() – Aroo Apr 05 '20 at 09:45
  • Is there a reason why you don't want to use `rand()`? Although it is open to criticism, for many purposes it is fine. If when coding in C you only want to use `stdio.h` you will have to reinvent a lot of wheels... – Weather Vane Apr 05 '20 at 09:47
  • Yeah. Its just that in my project I am not allowed to just use library function without doing anything on my own – Aroo Apr 05 '20 at 09:49
  • Research "Linear Congruential Generator" and write one of your own. – rossum Apr 05 '20 at 15:22
  • @rossum thats whay i did... Thanks – Aroo Apr 06 '20 at 16:04

0 Answers0