Skip to content

Monte carlo C fix #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 5, 2018
Merged

Conversation

Gorzoid
Copy link
Contributor

@Gorzoid Gorzoid commented Oct 5, 2018

MonteCarlo in C was not implemented as described by the book. In the book we are told to use only the first quadrant to calculate pi. The C code produces a random range from -1 to +1. While the method stills works I think we should keep code to follow the algorithm as described by the book.

I also removed the incorrect formula where radius != 0.0 and replaced it with code to product random variables from 0 to radius.

Another smaller change was changing the return type to double. The function should only calculate pi and return it, there's no need for it to also print the estimation and how close it was, that can be left up to the main function.

Should only produce numbers in rande 0 -> radius not -1 -> +1
monte_carlo should return a double, printing code should be in main
@Gorzoid Gorzoid changed the title Monte carlo c fix Monte carlo C fix Oct 5, 2018
@Gathros Gathros merged commit f9158d4 into algorithm-archivists:master Oct 5, 2018
@Gathros
Copy link
Contributor

Gathros commented Oct 5, 2018

Thanks, looks good.

@june128 june128 added Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.) Hacktoberfest The label for all Hacktoberfest related things! labels Oct 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Hacktoberfest The label for all Hacktoberfest related things! Implementation Edit This provides an edit to an algorithm implementation. (Code and maybe md files are edited.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants