How to resolve the algorithm Random number generator (device) step by step in the M2000 Interpreter programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Random number generator (device) step by step in the M2000 Interpreter programming language

Table of Contents

Problem Statement

If your system has a means to generate random numbers involving not only a software algorithm   (like the /dev/urandom devices in Unix),   then: show how to obtain a random 32-bit number from that mechanism.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Random number generator (device) step by step in the M2000 Interpreter programming language

Source code in the m2000 programming language

Module checkit {
      Declare random1 lib "advapi32.SystemFunction036" {long lpbuffer, long length}
      Buffer Clear Alfa as long*2
      Print Eval(Alfa,0)
      Print Eval(Alfa,1)
      call void random1(alfa(0), 8)
      Print Eval(Alfa,0)
      Print Eval(Alfa,1)
}
checkit

Function Random2  {
      Declare CryptAcquireContext Lib "advapi32.CryptAcquireContextW" {long ByRefhProv,  pszContainer$,pszProvider$, long dwProvType, long dwFlags}
      Declare CryptReleaseContext Lib "advapi32.CryptReleaseContext" {Long hProv, Long dwFlags}
      Declare CryptGenRandom Lib "advapi32.CryptGenRandom" {Long hProv, Long dwLen, Long ByRef}
      Const PROV_RSA_FULL As Long = 1
      Const VERIFY_CONTEXT As Long = 0xF0000000&
      Buffer Clear RandomNum as Long
      Buffer Clear hProv as long
      Call Void CryptAcquireContext( hProv(0), "", "", PROV_RSA_FULL, VERIFY_CONTEXT)
      Call Void CryptGenRandom( Eval(hProv,0), 4, RandomNum(0))
      Call Void CryptReleaseContext(Eval(hProv,0), 0&)
      =Eval(RandomNum,0)
}
Print Random2()

  

You may also check:How to resolve the algorithm Entropy step by step in the Groovy programming language
You may also check:How to resolve the algorithm Long year step by step in the TypeScript programming language
You may also check:How to resolve the algorithm Resistor mesh step by step in the Nim programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the Golo programming language
You may also check:How to resolve the algorithm Middle three digits step by step in the Plain English programming language