Monte-Carlo algorithm is a generalized method that can be used in many applications. It is a randomize approach. To compute the mathematics constant , we can use the method that is based on the probability.
See more posts here, here and here.
The below is a quick coding exercise for VBScript, that runs on mainly windows platform e.g. Windows Scripting Host. VBScript (not VB) is one of my favourite programming language because of: simplicity and no installation required for windows (in bundle with most Windows versions).
Also, VBScript is highly frequent used in ASP (Server side), VBA (for Microsoft Office) etc.
Monte-Carlo Compute PI – VBScript Version
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ' HelloACM.com rocks ' Monte-Carlo Compute PI - VBScript Version Dim cnt: cnt = 0 Dim i, x, y Const N = 1000000 Randomize For i = 1 To N x = Rnd y = Rnd If x * x + y * y <= 1.0 Then cnt = cnt + 1 End If Next MsgBox "PI = " & (4.0 * cnt / N) |
' HelloACM.com rocks ' Monte-Carlo Compute PI - VBScript Version Dim cnt: cnt = 0 Dim i, x, y Const N = 1000000 Randomize For i = 1 To N x = Rnd y = Rnd If x * x + y * y <= 1.0 Then cnt = cnt + 1 End If Next MsgBox "PI = " & (4.0 * cnt / N)
Just save the above file in *.vbs and double click (interpreted using C:\windows\system32\cscript.exe, or wscript.exe, or the same files under C:\windows\syswow64, i.e. run 32-bit interpreter under 64-bit windows).
If everything goes well, you will see a messagebox pop up:
Monte Carlo Simulation Algorithms to compute the Pi based on Randomness:
- Teaching Kids Programming – Area and Circumferences of Circle and Monte Carlo Simulation Algorithm of PI
- Using Parallel For in Java to Compute PI using Monte Carlo Algorithm
- Monte Carlo solution for Mathematics × Programming Competition #7
- R Programming Tutorial – How to Compute PI using Monte Carlo in R?
- C++ Coding Exercise – Parallel For – Monte Carlo PI Calculation
- Area of the Shadow? – The Monte Carlo Solution in VBScript
- VBScript Coding Exercise – Compute PI using Monte Carlo Random Method
- Computing Approximate Value of PI using Monte Carlo in Python
- How does the 8-bit BASIC perform on Famicom Clone – Subor SB2000 – FBasic – Compute PI approximation using Monte-Carlo method
- GoLang: Compute the Math Pi Value via Monte Carlo Simulation
- BASH Script to Compute the Math.PI constant via Monte Carlo Simulation
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: It takes 5 hours on a 8-bit famicom clone (SB2000) to compute 80 decimal places of PI
Next Post: Flash Your Webpage Title - Javascript Code Snippet