Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,124 members, 7,818,371 topics. Date: Sunday, 05 May 2024 at 01:49 PM

Help A Newbie - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help A Newbie (1681 Views)

Programmers In Ilorin!!!! Help A Newbie / Help Needed ... A Newbie In Php And Javascript / Help A Newbie Php Programmer (2) (3) (4)

(1) (Reply) (Go Down)

Help A Newbie by lifeisgood32: 5:49pm On Jul 27, 2012
Hello programmers in the house, please i need help with this algorithm, it's a problem from a fair die rolled, i obtained the variance and the process generator.
Hence i was able to get the monte Carlo algorithm.

But the issue here is i am to implement it in any programming of my knowledge, am only familiar with python which am still a learner but it's not to be used. Required language is either c++ or java.

input: number of random rolls of a fair die in the simulation

output: The percentage of probability for rolls {1,2,3,4,5 nd 6}

step1 : initialize the random variables J1, J2, J3, J4, J5 ,J6 that will be used to count the random deviates in the six intervals respectively, i.e J1=0, J2=0, J3=0, J4=0, J5=0, J6=0;

step2: for i=1, 2,......n do step3 and step4

Step3: Obtain a random number, r0 satisfying ( 0 <= r <= 1 )

Step4: if (0 < r < 1/6) Then
J1 = J1 + 1
else if (1/6 < r < 2/6 ) Then
J2 = J2 + 1
else if ( 2/6 < r < 3/6 ) Then
J3 = J3 + 1
else if ( 3/6 < r < 4/6 ) Then
J4 = J4 + 1
else if ( 4/6 < r < 5/6 ) Then
J5 = J5 + 1
else
J6 = J6 + 1
endif

Step5: Calculate the probabilities of each roll as Ji/n, i = 1 (1) 6

Step6: Output probabilities

Stop.

Well please i just downloaded code blocks ide now and trying to get round it, please esteemed programmers in the house help a newbie out.

I would appreciate if given how to go about it so i can try and see if i can code it myself.
Re: Help A Newbie by lordZOUGA(m): 6:22pm On Jul 27, 2012
is your problem setting up your development enviroment or coding the problem... I can help you do this in C++ by the way..
Re: Help A Newbie by lifeisgood32: 11:04pm On Jul 27, 2012
Well i dont even know how to set the environment here with code block.
Re: Help A Newbie by lordZOUGA(m): 11:14pm On Jul 27, 2012
follow the instructions on this page http://www.cprogramming.com/code_blocks/
Re: Help A Newbie by lifeisgood32: 4:25am On Jul 28, 2012
Okay i now see why my own couldn't run. I didnt install MINGW compiler. Thks will try and download that as soon as possible.
So can u help we with how i would write it in c++
Re: Help A Newbie by ektbear: 5:39am On Jul 28, 2012
Here is a python version: http://pastebin.com/0gC8V1DC

I guess you can probably translate that into Java or C++ with some googling of how to generate a uniform random variable in Java or C++.
Re: Help A Newbie by ektbear: 5:45am On Jul 28, 2012
Actually I like this version slightly better: http://pastebin.com/DNP8KAq6
Re: Help A Newbie by lifeisgood32: 10:04am On Jul 28, 2012
i dont get it. Am i to paste my code in python there to convert it?
Re: Help A Newbie by lordZOUGA(m): 12:06pm On Jul 28, 2012
your specifications are not really clear.
you wrote "percentage" of probability..
Re: Help A Newbie by lifeisgood32: 12:20pm On Jul 28, 2012
ok lets say parts, pls can u help me wit the codes in c++.
i need to study this so i can have a little knowledge, have less time to start learning c++, may be later.
Re: Help A Newbie by lordZOUGA(m): 6:06pm On Jul 28, 2012
check this out: http://pastebin.com/zg8HC9hf
it has not been tested. No power in my PC. If it doesn't compile or if this is not what you want indicate
Re: Help A Newbie by lordZOUGA(m): 12:01am On Jul 29, 2012
seems as if generating a random float number is complicated...
Re: Help A Newbie by ektbear: 6:59am On Jul 29, 2012
lifeisgood32: i dont get it. Am i to paste my code in python there to convert it?


You click the link, read the code, understand it, download it, run it, then translate it into Java or C++ (possibly doing some googling to figure out stuff in Java or C++ that you don't know).

Or, you can use lordZOUGA's code, fixing and modifying it as necessary to suit your purposes.
Re: Help A Newbie by lifeisgood32: 1:14pm On Jul 29, 2012
This is the message i see in the build log: toolchain path within the compiler options is not setup correctly! Skipping
nothing to be done.

Please wat should i do? Am using code blocks version 10.05
Re: Help A Newbie by lordZOUGA(m): 5:17pm On Jul 29, 2012
lifeisgood32: This is the message i see in the build log: toolchain path within the compiler options is not setup correctly! Skipping
nothing to be done.

Please wat should i do? Am using code blocks version 10.05
I don't use code::blocks IDE but I suppose there should be an options where you can specify a path to your build tools. Locate the mingw folder a set any folder that contains g++ as your build path
Re: Help A Newbie by ektbear: 8:58am On Jul 30, 2012
Bros...installing an IDE should not be this complicated.

Google and read the instructions, then follow them exactly.

Regarding the code, given that you have two implementations to work with, it shouldn't be hard for you to complete the project now..
Re: Help A Newbie by lifeisgood32: 1:09pm On Aug 03, 2012
Okay i have my ide up and running now thanks.
but this is the error i encountered when i compiled the code

Re: Help A Newbie by lordZOUGA(m): 3:40pm On Aug 04, 2012
okay... Glad you fixed your IDE... Could have fixed the code a while ago but I wasn't about to waste my time for someone who wasn't interested...
Here is the fixed code... Debugged and tested: http://pastebin.com/Wa5wCzkH
Re: Help A Newbie by lifeisgood32: 6:45pm On Aug 04, 2012
Wow thanks i have it running now, i can use this to solve the second work i have and hope i wont have issues, thanks

Re: Help A Newbie by lordZOUGA(m): 7:37pm On Aug 04, 2012
okay. But you will only get a truly random distribution for a sufficiently large value of n
Re: Help A Newbie by lifeisgood32: 7:46pm On Aug 04, 2012
Okay thanks for your time.

Yes i know i just tried it with 6 to see what the result will be. Let me get down to work on the main deal.
Re: Help A Newbie by lifeisgood32: 11:26am On Aug 12, 2012
please lordZOUGA i have a small issue doing another project.
Am to write a program to simulate the demands for the next 100days.

I was given the demand and probability function. Can i tweak the code u gave me to do this?
Am on mobile now will try upload the codes i wrote and the error i encountered.
Re: Help A Newbie by lordZOUGA(m): 1:16pm On Aug 12, 2012
lifeisgood32: please lordZOUGA i have a small issue doing another project.
Am to write a program to simulate the demands for the next 100days.

I was given the demand and probability function. Can i tweak the code u gave me to do this?
Am on mobile now will try upload the codes i wrote and the error i encountered.
I don't get your problem though.. I will advice you to change the title of this thread to something more particular to this thread..
Re: Help A Newbie by lifeisgood32: 4:11pm On Aug 12, 2012
okay will do that now.

(1) (Reply)

His Mysql Query Returned Duplicate Output. Help Him / Building An Ai(artificial Intelligence) / Codeigniter Vs Wordpress – Make The Right Web Development Platform Selection

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 22
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.