2

At this point i have been learning assembly for about 6 months. My current project is a random number generator. I need to generate 1 random number in 0 to 256 range. I have tried this: mov ax,[Clock] mov [rng],al This did not work since the clock is giving me 0. I have tried to learn other methods with no avail. My question is how do i make it work?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Rotem
  • 21
  • 1
  • There's a value in the BDA telling you how often a timer interrupt has fired since boot. Perhaps you could use that? – fuz May 23 '20 at 11:04
  • I have tried , it didnt seem to work aswell. – Rotem May 23 '20 at 11:08
  • Have you tried using the `01Ah` BIOS interrupt instead? https://stackoverflow.com/questions/25952740/how-to-get-bios-time-using-assembly – Tobias May 23 '20 at 12:39
  • 3
    I wrote a related answer here: https://stackoverflow.com/a/47613489/3857942 . The last example in my answer has an assembly function `srandsystime` `rand` and `rand2num1to10` (this can be modified to return a val between 0-255) written in 16-bit assembly. It is a simple LCG and not meant for crypto or securit application. Should suffice for simple games. Although that answer uses EMU8086, EMU8086 specific stuff was just related to printing values to the screen. The 3 rand functions can be taken and put in a 16-bit TASM assembly source file with little effort. – Michael Petch May 23 '20 at 13:56
  • My answer also links to some other related SO answers and some external reading material. – Michael Petch May 23 '20 at 18:25
  • 1
    How random? More recent intel and amd cpus have an instruction for that: https://en.wikipedia.org/wiki/RDRAND – President James K. Polk May 23 '20 at 19:08
  • @Rotem Please show what you tried. This should definitely work. – fuz May 23 '20 at 20:39

0 Answers0