|
|
If you have a specific question, ask it. Otherwise, I'm sure you can figure it out or Google it.
|
|
|
|
|
i just didnt get your previous message:
I've read his posts and don't see a single impolite thing. Good luck with your approach - you'll need it. You might try reviewing your well worn copy of Dale Carnegie
what do you mean?
FMZL
|
|
|
|
|
As I said, you could Google it. Dale Carnegie is famous for a book called "How to Win Friends and Influence People".
|
|
|
|
|
Ok, someone has already asked this question of you, but I need some clarification. When you say "generate a number which is in group A for 30% of time", do you mean:
a. Every iteration there is a 30% chance that the number will come from group A
b. If I do 100 iterations, 30 of these numbers will definitely be from group A
These two interpretations are very different and will require different solutions, so I need some clarification before helping you further.
|
|
|
|
|
I meant if I do 100 iterations, 30 of these numbers will definitely be from group A, not more than or less than 30 exactly 30, which is actually option "b", but Im interested to know the solution for option "a", I think its useful for the program im working on.
Thanks
FMZL
|
|
|
|
|
option a is solved in my very first reply to you.
option b is impossible, unless the number of runs is a multiple of 10.
|
|
|
|
|
"option b is impossible, unless the number of runs is a multiple of 10" - then it's not really impossible, is it?
@fzml
Option A:
Ok, for Option A, Luc's solution is what I'd go with (in fact I can't think of another way off the top of my head, at least one that's not contrived). Assume we have two sets of numbers, A and B. We want 30% chance of selecting something from A, and 70% chance of selecting something from B: in pseudo-C#, something like:
1 Random rnd = new Random();
2
3 int selector = rnd.Next(1, 10);
4
5 if (selector <= 3) {
6 else {
As you can see, the rnd.Next has 10 possible outputs (1, 2, 3 ... 10) - we assign 30% of those, i.e. 1 through 3, to our 30% group. The rest make up the 70% for the other group.
If we wanted 3 groups with (A: 20%, B: 50%, C: 30%):
1 Random rnd = new Random();
2
3 int selector = rnd.Next(1, 10);
4
5 if (selector in {1, 2}) {
6 else if (selector in {3, 4, 5, 6, 7}) {
7 else {
By splitting a known number of outcomes up like this, you can have "pre-determined probabilities". Of course, this all relies on the soundness of the Random generator you're using. If you would like to write your own, there's heaps of literature out there on the web about RNGs (check out the Mersenne Twister).
Option B:
Well, Option B (forgive me if I get the wrong terminology here) is about creating a pseudo-random number generator, with period of x, that selects members randomly from different sets based on enforced probabilities.
Ok, well let's say you have two sets A and B:
1 A = { 1, 2, 3, 4 }
2 B = { 5, 6, 7, 8 }
You need to set a "period", that is, what number of interations will satisfy the exactness of our probabilities (for example, up until now we have assumed 100 iterations will satisfay the probabilities).
So, let's say we pick 100 - that means every 100 iterations, we can look at our results and say for sure that 30% of these will be from A and the rest from B.
A very simple way, based on Option A, would be (pseudo-code):
1. Generate a list of numbers, 1 through 100
2. [[Generate a random integer between 1 and 100]] to select one of these numbers
3. If the random number is not in our list
a) [[Get a number that IS in the list]]
4. If the number we selected is in range 1 - 30, then [[select one from group A]]
5. If the number we selected is in range 31 - 100, then [[select one from group B]]
6. Remove the number from our list!
7. If the list is empty, regenerate it with 1 through 100
Ok, so anything wrapped in square brackets ([[ and ]]) is to indicate that you can do those parts however you want, i.e. it does not matter how you generate your random numbers or how you select from each group etc. This does not affect your requirements.
Anyway, Option B is essentially using the same technique as Option A - use a random number as a way to SELECT a result, rather than as the result itself.
E-mail or reply if you're still lost, I'll try and knock up some code for you to demonstrate better.
|
|
|
|
|
|
No worries mate, you could extend option B to do this every 1000, 5000, 10000 etc. iterations. Just as long as you can divide up your selectors wholly between each group, you're home and hosed!
Hope I helped, again, if you would like more explanation or an example, just email me or post again
|
|
|
|
|
You got lucky.
|
|
|
|
|
I don't understand what you mean, Luc. Could you explain your comment?
|
|
|
|
|
you got upvoted, I got downvoted for no apparent reason. As you told him my answer was OK, he should have downvoted you too. Lots of spoons may have saved your skin.
|
|
|
|
|
However, remember that there's no such thing as bad questions, only bad answers, and everyone's prone to giving them. No need to be upset or insult someone when they don't understand you, simply ask how you can help to further explain yourself
Keep in mind there's not much resolution when it comes to voting on answers, it's either "good" or "bad", no in-between. There should be another button "I don't get it", "please explain" or simply "Pauline Hanson" (Australian political reference).
|
|
|
|
|
Downvoting is not insulting someone, its just a way to say that this is not the solution for my problem, I think CodeProject has these two buttons ("Good Answer" and "Bad Answer")just for saying that a solution is useful or not, nothing else. so dont get offended by these things, but when you say someone sounds impolite and dumb because he just didnt vote 5 to your answer is an insult or saying "you sound dumber because of using u instead of you" is impolite and im my point of view is counted as an insult. Anyway thanks to everyone who helped me on this problem, specially NickHighIQ.
Thnx
FMZL
|
|
|
|
|
Downvoting someone does not make anyone 'impolite and dumb'. What makes anyone that is: Not explaining what's wrong with the given answer and what's actually expected. After downvoting the answer, a 'polite and intelligent' reply like "Thanks for your efforts but what I really want is..." could have made things a lot smoother for everyone.
Regarding the use of sms lingo, plz undrstnd dat dis site is read by ppl across da world, 4 many of whom English s not da 1st lang. U wud ugree dat if every1 starts using dis kinda lang then life will b hell 4 all of us. Dat's y v discourage sms lingo.
It's better to know some of the questions than all of the answers.
Pravin.
|
|
|
|
|
can we please stop arguing about this downvoting?
I recieved 100 of messages but only 2 of them are the answerws to my question. I ask a question and i recieve answers, the one that helps ME will get 5 and the one that doesn't will get 1. next time i will post my questions on msdn or somewhere else, because people here are really act like elementary school students and just looking for EXTRA MARKS. Mr.PravinSingh we are not here to give each other life lessons or advices, we are here to talk about COMPUTER PROGRAMMING, and I thought this argu was over but you like to continue it. and finally that last 2.5 lines dont make any sense to me because as i remember i just used "u" instead of "you" not any of the other words that you wrote there.
FMZL
|
|
|
|
|
I didn't mean to offend you. What I said was just a friendly advice on how you can avoid getting into useless discussions and what will fetch you more answers; it was "life lessons" as you call it. But since you don't want it, we should stop the discussion here.
I apologize for giving you unwanted advice.
It's better to know some of the questions than all of the answers.
Pravin.
|
|
|
|
|
How did you make those green code blocks with each line numbered?
|
|
|
|
|
Sorry mate, I replied under Luc's post - come check out the page, I've answered your question (I hope!)
|
|
|
|
|
This is the first random number generation method they usually teach in an introductory simulation course. Think it's called Aliasing or something like that.
|
|
|
|
|
Hi,
I need to find a goal given the following conditions
-I only know my 4 surroundings (N,W,S,E): they can be empty or an obstacle
-I know the goal coordinates (x,y)
-I know my coordinates
I know bug-2 (and bug-1) are complete algorithms (they always find the goal).
But it is really bad in some maps with large obstacles.
My questions are two.
1. How come there arent quick and well-known solutions to this? Ive been googling for ages and I just find theoretical papers, full of blabla and no pseudocode.
2. A* wouldnt work for this because of my first restriction, right?
Thanks
|
|
|
|
|
I'm sure A* would work - all it requires is to know if a neighbouring tile is walkable or not, and then a cost for moving there. (Sidenote: you could substitute this for simply assigning a cost to moving across each tile and make impassable obstacles have infinite cost?)
Anyway, here's a good A* link: http://www.policyalmanac.org/games/aStarTutorial.htm
This is 8-directional, but it will work exactly the same in 4-directional.
|
|
|
|
|
Hi
You can represent this as a Graph-problem(some kind of shortest path algorithm)
You can apply these restrictions while moving
1 . Trace your current path, if the new slot is in the current path ignore that to avoid a loop
2 . Mark the positions in which no further movements are possible so that we can ignore that.
3 . If we have no further move retract your move using a stack
Back-tracking may not be an optimal solution, but you can apply some restrictions to improve it
Thanks
|
|
|
|
|
Compression is the key; it was mentioned on the page you linked to. MPEG is JPEG for moving images. What you do is trade in a lot of bandwidth for a gigantic lot of computations, and throw away some of the information (just like JPEG does).
|
|
|
|
|