Hi,
If I generate a random number in cell A1 ranging from 1 to 3
Can I count how many times the result is equal to 2
if I was to run it 100 times and then show the results in cell A3.
Regards
Steve
Hi,
If I generate a random number in cell A1 ranging from 1 to 3
Can I count how many times the result is equal to 2
if I was to run it 100 times and then show the results in cell A3.
Regards
Steve
Last edited by gadjit; 09-22-2009 at 09:01 AM.
![]()
Please Login or Register to view this content.
You don't need to actually put the random number into the cell on the sheet, that slows things down needlessly. Once you start to use VBA, you can do it all in VBA and then just put the results onto the sheet.
![]()
Please Login or Register to view this content.
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc
?Actually, I *am* a rocket scientist.? - JB (little ones count!)
The
If Evaluate("=RANDBETWEEN(1,3)") = 2 Then c = c + 1
Gave me a type mismatch.
anyone else get that?
It works for me on Excel 2003. Here's an alternate technique you can use:
Excelguy, does this even work for you:![]()
Please Login or Register to view this content.
If you don't get a popup saying "1" then you can't use the Evaluate() function.![]()
Please Login or Register to view this content.
Last edited by JBeaucaire; 09-21-2009 at 01:22 PM.
Yep, the Sub Test worked for me. I'll have to try the other example you gave. but if the Evaluate function worked then there should be no reason why the first example would have an issue right?
Here is an example I put together after much help from the Forum, thanks for your help.
Is there any reason I find number 1 & 10 do not appear as often as the rest?
Your use of ROUND halves the probabilities of the endpoints.
If you want uniform distribution between 1 and 10,
=int(rand()*10) + 1
Entia non sunt multiplicanda sine necessitate
thanks, it work a treat.
Is there a simple way to improve this code so that it also tells on which attempts number 2 came up? Basically I have to create a code for throwing dice (random numbers 1-6) 100 times and count how many times number two is thrown and also on which attempts.
flm,
Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
If I have helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks