How to take the output of throwing dice [closed] - probability

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to display the outcome of throwing a dice with equal probability of 1,2,3,4,5,6 ?
Random no does not display with equal probability.
Thanks in advance.

If you have a reasonably good PRNG (pseudo-random number generator), you should be able to do something like (where % is the modulo operator):
print( good_prng() % 6 + 1 )
Some basic PRNGs aren't very random in the lower order bits. Without knowing what language and PRNG you're using, it's hard to say if this is the reason for what you're observing.
In Python (asked for in comment):
import random
print( random.randint(1,6) )
Python's random module uses a Mersenne twister, which is a very good PRNG.

Related

How does Ruby generate random numbers using [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
So when using, for example, rand(10), how does ruby generate the random number? I have very little knowlege about random number generation techniques, so I would like to get to know them better.
Ruby is open-source. I'll demonstrate how to locate the PRNG (pseudo random number generator) code, as there's no way to generate truly random numbers using a deterministic CPU.
Looking at the repository, we see a suspiciously-named file, random.c. Looking inside, it's in C, but that's ok, it has comments. The first function is genrand_real, calling genrand_int32, which takes a struct MT. This function is defined in mt19937.c and looking at that file, it uses bitwise operations to get the next state of the random number generator and applies more bitwise operators to generate the number desired.

Real time applications for counting numbers [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am solving interesting questions which are quite frequently asked in programming interview like following:
Compute sum of digits in all numbers from 1 to n?
Compute number of perfect square between two given numbers?
Count numbers from 1 to n that have 4 as a digit?
I am wondering what are real time applications for above? Can any one please share there views.
I think these questions have multiple solutions. Question 1 and 3 are interesting because you can solve these problems without iteration in very clever ways, but also solve them using very long winded ways. As someone who does a lot of interviewing, I would want use this type of question to gauge the sophistication of the candidate at solving problems. On that basis I don't think giving you a clever answer to these question is going to be in your best interests to succeeding at interviews. How you tackle a problem and how far you can push the boundaries is what is likely being tested.

Pso based image enhacment [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I want to enhance my image by using pso based gray level image enhacment.I send the algorithm but i dont understand how I get particle of my image.pso paper
You only need to carefully read the section B. Proposed methodology. It says something like this:
Now our aim is to find the best set of values
for these four parameters which can produce the optimal result
and to perform this work PSO is used. P number of particles
are initialized, each with four parameters a, b, c, and k by the
random values within their range and corresponding random
velocities.
So there you have your particle generation. Each particle is a set of 4 random values.

What is the function of state in a pseudorandom number generator? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm working on a pseudorandom number generator for an assignment and I'm having a hard time wrapping my head around how state is used in it. What does it mean to advance to the next one? I'm not looking for tips on implementation, just an explanation of the concept. Thanks!
A PRNG generates a sequence of numbers.
To calculate the next number, you have some internal state (variables set to specific values, if you will). That's the state referred to in the context of PRNG. This state can often be represented by just a single number.

Expanding an arthimetic algorithm for a Weightlifting [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
So I am a quite novice programmer, I have been teaching myself Ruby for a couple of weeks now, and I made a program that estimates your 1 repetition max possible weight lifting capabilities.
The algorithm I used is:
weight = gets.to_i
reps = gets.to_i
x=Rational(reps,30)
x=x.to_f
one_RM = weight*(1+x)
Now this has worked well to get an estimate equal to other 1rep max calculators out there, but what I want to do is to make it so that it takes any weight and reps value and lets the user choose which rep range to convert to.
If that was unclear here is an example of what I mean:
user writes 100 kg and 10 reps program prompts the user for a rep value it would like to get an estimate for, eg instead of only 1rm it can predict anything from 1-100rm etc.
here is a series of formulas for how to calculate the 1 rep maximum:
http://en.wikipedia.org/wiki/One-repetition_maximum#Calculating_1RM
I tried looking trough them and see if I could come up with an idea, but I'm not an expert at math(understatement) and I am very new to programming, so my brain is not contributing any useful solutions, any insights greatly appreciated!
You need to compute the 1RM and then invert the formulas you link to using the new value if r (the number of repetitions your user wants to do).
So with the formula you're using, and r_asked and w_asked the values for repetitions and weight :
You now need to do :
w_asked = one_RM / (1+ r_asked/30)

Resources