Search Results

Search found 11277 results on 452 pages for 'jeff certain'.

Page 43/452 | < Previous Page | 39 40 41 42 43 44 45 46 47 48 49 50  | Next Page >

  • How do I generate a random string of up to a certain length?

    - by slavy13
    I would like to generate a random string (or a series of random strings, repetitions allowed) of length between 1 and n characters from some (finite) alphabet. Each string should be equally likely (in other words, the strings should be uniformly distributed). The uniformity requirement means that an algorithm like this doesn't work: alphabet = "abcdefghijklmnopqrstuvwxyz" len = rand(1, n) s = "" for(i = 0; i < len; ++i) s = s + alphabet[rand(0, 25)] (pseudo code, rand(a, b) returns a integer between a and b, inclusively, each integer equally likely) It doesn't work because shorter lengths are as likely as longer ones, meaning it's more likely to generate a shorter string than a longer one, so the result is not uniform.

    Read the article

  • How to make code run a certain amount of times before returning something?

    - by user3564967
    I made a trivia game and I have to make a method (SuccessOrFail) that will return whether the user beat the trivia or not. namespace D4 { /// <summary> /// Displays the trivia and returns whether the user succeeded or not, number of questions asked, and a free piece of trivia. /// </summary> public partial class TriviaForm : Form { private Trivia trivia; private Question question; private Random rand = new Random(); private HashSet<int> pickedQuestion = new HashSet<int>(); private string usersAnswer; private int numCorrectAnswers; private int numIncorrectAnswers; public TriviaForm() { InitializeComponent(); this.trivia = new Trivia(); QuestionRandomizer(); QuestionOutputter(); } /// <summary> /// This method will return true if succeeded or false if not. /// </summary> /// <returns>Whether the user got the trivia right or not</returns> public bool SuccessOrFail(bool wumpus) { bool successOrFail = false; int maxQuestions = 3; if (wumpus == true) maxQuestions = 5; int numNeededCorrect = maxQuestions / 2 + 1; if (this.usersAnswer == question.CorrectAnswer.ToString()) numCorrectAnswers++; else numIncorrectAnswers++; if (numCorrectAnswers + numIncorrectAnswers == maxQuestions) { if (numCorrectAnswers == numNeededCorrect) successOrFail = true; else successOrFail = false; numCorrectAnswers = 0; numIncorrectAnswers = 0; return successOrFail; } else return false; } /// <summary> /// This method will output a free answer to the player. /// </summary> public string FreeTrivia() { return question.Freetrivia; } // This method tells the player whether they were correct or not. private void CorrectOrNot() { if (this.usersAnswer == question.CorrectAnswer.ToString()) MessageBox.Show("Correct"); else MessageBox.Show("Incorrect"); } // Displays the questions and answers on the form. private void QuestionOutputter() { this.txtQuestion.Text = question.QuestionText; this.txtBox0.Text = question.Answers[0]; this.txtBox1.Text = question.Answers[1]; this.txtBox2.Text = question.Answers[2]; this.txtBox3.Text = question.Answers[3]; } // Clears the TextBoxes and displays a new random question. private void btnNext_Click(object sender, EventArgs e) { this.usersAnswer = txtAnswer.Text; CorrectOrNot(); this.txtQuestion.Clear(); this.txtBox0.Clear(); this.txtBox1.Clear(); this.txtBox2.Clear(); this.txtBox3.Clear(); this.txtAnswer.Clear(); this.txtAnswer.Focus(); QuestionRandomizer(); QuestionOutputter(); this.txtsuc.Text = SuccessOrFail(false).ToString(); } // Choose a random number and assign the corresponding data to question, refreshes the list if all questions used. private void QuestionRandomizer() { if (pickedQuestion.Count < trivia.AllQuestions.Count) { int random; do { random = rand.Next(trivia.AllQuestions.Count); } while (pickedQuestion.Contains(random)); pickedQuestion.Add(random); this.question = trivia.AllQuestions.ToArray()[random]; if (pickedQuestion.Count == trivia.AllQuestions.ToArray().Length) pickedQuestion.Clear(); } } } } My question is how to make it so that the code asks the user 3 or 5 questions and then returns whether the user won or not? I was wondering if somehow I could make a public void that would just make the form pop up and ask the user 3 to 5 questions and then once it asks the maximum number of questions, to close and then have a method that returns true if the user won, or false if they didn't. But I literally have no idea how to do that. Edit: So I know a for loop can make code run more than once. But the problem I'm having is, is that I don't know how to make it so that the trivia game asks 3 to 5 questions BEFORE returning something.

    Read the article

  • What are the best security measures to take for making certain directories private?

    - by Sattvic
    I have a directory on my server that I do not want Search Engines to crawl and I already set this rule in robots.txt I do want people that have logged in to be able to have access to this directory without having to enter a password or anything. I am thinking that a cookie is the best thing to put on users computers after they login, and if they have a cookie, they can access the directory. Is this possible, or is there a better way? I want people without this cookie to not have access to this directory - access for members only Any suggestions on the best design for this?

    Read the article

  • Delete the last instance of a certain string from a text file without changing the other instances o

    - by fraXis
    Hello, I have a C# program where I am using a lot of RegEx.Replace to replace text in my text file. Here is my problem. In my text file, I have a code such as "M6T1". This code is listed in numerous places in the text file. However, I only want to delete it from the bottom (last instance) in the text file. There will always be a "M6T1" at the bottom of the text file, but it is not always the last line. It could be the 3rd line from the bottom, the 5th line from the bottom etc. I only want to get rid of the last instance of "M6T1" so RegEx.Replace won't work here. I don't want to interfer with the other "M6T1"'s in the other locations in the text file. Can someone please give me a solution to this problem? Thanks

    Read the article

  • How to detect if a certain range resides (partly) within an other range?

    - by Tom
    Lets say I've got two squares and I know their positions, a red and blue square: redTopX; redTopY; redBotX; redBotY; blueTopX; blueTopY; blueBotX; blueBotY; Now, I want to check if square blue resides (partly) within (or around) square red. This can happen in a lot of situations, as you can see in this image I created to illustrate my situation better: Note that there's always only one blue and one red square, I just added multiple so I didn't have to redraw 18 times. My original logic was simple, I'd check all corners of square blue and see if any of them are inside square red: if ( ((redTopX >= blueTopX) && (redTopY >= blueTopY) && (redTopX <= blueBotX) && (redTopY <= blueBotY)) || //top left ((redBotX >= blueTopX) && (redTopY >= blueTopY) && (redBotX <= blueBotX) && (redTopY <= blueBotY)) || //top right ((redTopX >= blueTopX) && (redBotY >= blueTopY) && (redTopX <= blueBotX) && (redBotY <= blueBotY)) || //bottom left ((redBotX >= blueTopX) && (redBotY >= blueTopY) && (redBotX <= blueBotX) && (redBotY <= blueBotY)) //bottom right ) { //blue resides in red } Unfortunately, there are a couple of flaws in this logic. For example, what if red surrounds blue (like in situation 1)? I thought this would be pretty easy but am having trouble coming up with a good way of covering all these situations.. can anyone help me out here? Regards, Tom

    Read the article

  • How to sort a multidimensional array by a certain key?

    - by Eelke
    This should be really simple, but what is the way to go on this. I want to sort an multidimensional array by a key, like this: Array ( [0] => Array ( [iid] => 1 [invitee] => 174 [nid] => 324343 [showtime] => 2010-05-09 15:15:00 [location] => 13 [status] => 1 [created] => 2010-05-09 15:05:00 [updated] => 2010-05-09 16:24:00 ) [1] => Array ( [iid] => 1 [invitee] => 220 [nid] => 21232 [showtime] => 2010-05-09 15:15:00 [location] => 12 [status] => 0 [created] => 2010-05-10 18:11:00 [updated] => 2010-05-10 18:11:00 )) Say i want to sort this by [status], how would I achieve this? Thanks in advance!

    Read the article

  • How do I select the last child of a div with only a certain name using only CSS?

    - by Jared
    Hello, I have been using the following CSS to apply an effect at the bottom of elements in a menu: .leftMenuProductWrapper div:last-child{margin-bottom:20px;} This works fine initially, however after adding more elements in the menu, I realized it was a problem. I really only want to select the last div with .leftMenuProductButton within .leftMenuProductWrapper Anyway to do this without using Jquery, just pure CSS?

    Read the article

  • What is the XSLT to write certain node attributes one-to-a-line?

    - by Scott Stafford
    I want an XML stylesheet (XSLT) that will put the attributes of a few, specific, child nodes one-to-a-line. What is the XSLT for this? I recently asked a related question that someone offered a stylesheet to solve but their stylesheet didn't work for some reason, and I am curious why -- the attributes simply didn't end up one-per-line. By way of example, my XML might look like this: <MyXML> <NodeA> <ChildNode value1='5' value2='6' /> </NodeA> <NodeB> <AnotherChildNode value1='5' value2='6' /> </NodeB> <NodeC> <AnotherChildNode value1='5' value2='6' /> </NodeC> </MyXML> And I want a stylesheet that will expand all NodeA's and NodeB's but not NodeCs and make it look like this: <MyXML> <NodeA> <ChildNode value1='5' value2='6' /> </NodeA> <NodeB> <AnotherChildNode value1='5' value2='6' /> </NodeB> <NodeC> <AnotherChildNode value1='5' value2='6' /> </NodeC> </MyXML>

    Read the article

  • How can I check with a regex that a string contains only certain allowed characters?

    - by Camran
    I need a special regular expression, have no experience in them whatsoever so I am turning to you guys on this one: I need to validate a classifieds title field so it doesn't have any special characters in it, almost. Only letters and numbers should be allowed, and also the swedish three letters å, ä, ö, and also not case sensitive. Besides the above, these should also be allowed: The "&" sign. Parenthesis sign "()" Mathematical signs "-", "+", "%", "/", "*" Dollar and Euro signs One accent signed letter: "é". //Only this one is required Double quote and singel quote signs. The comma "," and point "." signs Thanks

    Read the article

  • How can I sort an array, yet exclude certain elements (to be kept at the same position in the array)

    - by calumbrodie
    This will be implemented in Javascript (jQuery) but I suppose the method could be used in any language. I have an array of items and I need to perform a sort. However there are some items in the array that have to be kept in the same position (same index). The array in question is build from a list of <li> elements and I'm using .data() values attached to the list item as the value on which to sort. What approach would be best here? <ul id="fruit"> <li class="stay">bananas</li> <li>oranges</li> <li>pears</li> <li>apples</li> <li class="stay">grapes</li> <li>pineapples</li> </ul> <script type="text/javascript"> var sugarcontent = new Array('32','21','11','45','8','99'); $('#fruit li').each(function(i,e){ $(this).data(sugarcontent[i]); }) </script> I want the list sorted with the following result... <ul id="fruit"> <li class="stay">bananas</li> <!-- score = 32 --> <li>pineapples</li> <!-- score = 99 --> <li>apples</li> <!-- score = 45 --> <li>oranges</li> <!-- score = 21 --> <li class="stay">grapes</li> <!-- score = 8 --> <li>pears</li> <!-- score = 11 --> </ul> Thanks!

    Read the article

  • How do I get certain code to execute before every single controller action in ASP.NET MVC 2?

    - by Chris
    I want to check some things about the state of the session, the user agent, etc, and possibly take action and return a special view BEFORE a controller method gets a chance to execute. For example: Most common: User requests Home/Index System checks to make sure x != 0. x does not equal zero, so the Home/Index controller executes like normal. But, sometimes: User requests Home/Index System checks to make sure x != 0. x DOES equal zero. The user must be notified and the requested controller action cannot be allowed to execute. I think this involves the use of ActionFilters. But I have read about them and I don't understand if I can preempt the controller method and return a view before it executes. I am sure I could execute code before the controller method runs, but how do I keep it from running in some instances and return a custom view, or direct to a different controller method?

    Read the article

  • JavaCC: How can I specify which token(s) are expected in certain context?

    - by java.is.for.desktop
    Hello, everyone! I need to make JavaCC aware of a context (current parent token), and depending on that context, expect different token(s) to occur. Consider the following pseudo-code: TOKEN <abc> { "abc*" } // recognizes "abc", "abcd", "abcde", ... TOKEN <abcd> { "abcd*" } // recognizes "abcd", "abcde", "abcdef", ... TOKEN <element1> { "element1" "[" expectOnly(<abc>) "]" } TOKEN <element2> { "element2" "[" expectOnly(<abcd>) "]" } ... So when the generated parser is "inside" a token named "element1" and it encounter "abcdef" it recognizes it as <abc>, but when its "inside" a token named "element2" it recognizes the same string as <abcd>. element1 [ abcdef ] // aha! it can only be <abc> element2 [ abcdef ] // aha! it can only be <abcd> If I'm not wrong, it would behave similar to more complex DTD definitions of an XML file. So, how can one specify, in which "context" which token(s) are valid/expected? NOTE: It would be not enough for my real case to define a kind of "hierarchy" of tokens, so that "abcdef" is always first matched against <abcd> and than <abc>. I really need context-aware tokens.

    Read the article

  • Why does Eclipse crash with Xmx, XX:MaxPermSize above certain values?

    - by alex
    Running Eclipse 3.5.1, JDK 1.6.0_17 on WinXP SP3 32Bit with 3.5 gigs of RAM. I'm aware of the known Eclipse best practices, still trying to figure out eclipse.ini. This will launch: -Xmx588m and this won't: -Xmx589m. Same with -XX:MaxPermSize. Anything above -XX:MaxPermSize=140m won't launch. The screen of death is simlar to this (taken from here). Any ideas on why might this be happening?

    Read the article

  • jQuery select image in div if image parent does't have a certain class.

    - by Alex
    Wordpress wraps images with captions in a div with a class of .wp-caption. I'm looking for a way to select images that don't have this div so I can wrap them in different div. (to keep a consistent border around all the images) <div class="blog-post-content"> <div id="attachment_220" class="wp-caption alignleft" style="width: 310px"> <a href="/somewhere/"><img class="size-medium wp-image-220" src="/path/to/image" alt="" width="300" height="280" /></a> <p class="wp-caption-text">Caption Text</p> </div> <p>This is the body of the post</p> </div> To test my selector, I'm just trying to add a green border. I can handle the .wrap() once the selector is working. The most promising of my attempts is: $('.blog-post-content img').parent('div:not(".wp-caption")').css('border', '2px solid green'); ... but no luck.

    Read the article

  • How would I create a VIM or Vi command to delete all text after a certain character for every line i

    - by Jason Down
    Scenario: I have a text file that has pipe (as in the "|" character) delimited data. Each field of data in the pipe delimited fields can be of variable length, so counting characters won't work (or using some sort of substring function... if that even exists in VIM). Is it possible, using VIM / Vi to delete all data from the second pipe to the end of the line for the entire file? There are approx 150,000 lines, so doing this manually would only be appealing to a masochist... e.g. Change the following lines from: 1111|random sized text 12345|more random data la la la|1111|abcde 2222|random sized text abcdefghijk|la la la la|2222|defgh 3333|random sized text|more random data|33333|ijklmnop to: 1111|random sized text 12345 2222|random sized text abcdefghijk 3333|random sized text I'm sure this can be done somehow... I hope. TIA UPDATE: I should have mentioned that I'm running this on Windows XP, so I don't have access to some of the mentioned *nix commands (CUT is not recognized on Windows).

    Read the article

  • Is there an algorithm for finding an item that matches certain properties, like a 20 questions game?

    - by lala
    A question about 20 questions games was asked here: However, if I'm understanding it correctly, the answers seem to assume that each question will go down a hierarchal branching tree. A binary tree should work if the game went like this: Is it an animal? Yes. Is it a mammal? Yes. Is it a feline? Yes. Because feline is an example of a mammal and mammal is an example of an animal. But what if the questions go like this? Is it a mammal? Yes. Is it a predator? Yes. Does it have a long nose? No. You can't branch down a tree with those kinds of questions, because there are plenty of predators that aren't mammals. So you can't have your program just narrow it down to mammal and have predators be a subset of mammals. So is there a way to use a binary search tree that I'm not understanding or is there a different algorithm for this problem?

    Read the article

  • Is there a way to cause a new C++ class instance to fail, if certain conditions in the contructor ar

    - by Jim Fell
    As I understand it, when a new class is instantiated in C++, a pointer to the new class is returned, or NULL, if there is insufficient memory. I am writing a class that initializes a linked list in the constructor. If there is an error while initializing the list, I would like the class instantiator to return NULL. For example: MyClass * pRags = new MyClass; If the linked list in the MyClass constructor fails to initialize properly, I would like pRags to equal NULL. I know that I can use flags and additional checks to do this, but I would like to avoid that, if possible. Does anyone know of a way to do this? Thanks.

    Read the article

  • Android: Find coordinates of a certain point X meters from my location moving towards the point I am

    - by Aidan
    Hi Guys, I'm constructing a geolocation based application and I'm trying to figure out a way to make my application realise when a user is facing the direction of the given location (a particular long / lat co-ord). I've done some Googling and checked the SDK but can't really find anything for such a thing. Does anyone know of a way? Example. Point A = Phones current location. Point B = A's orientation in relation to true north + 45 + max distance towards the direction your facing, Point C = A's orientation in relation to true north - 45 + max distance towards the direction your facing. So now you have a triangle constructed. pretty schweet huh? yeah.. I think so.. So now that I have my fancy Triangle I use something called Barycentric Coordinates ( http://en.wikipedia.org/wiki/Barycentric_coordinates_(mathematics) ). This will allow me to test another point and see if it is in the triangle. If it is, it means we're facing it AND it's within the right distance. So it should be displayed on screen. If I'm facing 90 degrees from true north. The distance it travels should be that direction. 90 degrees from true north. It should not be 100 degrees or something from true north! But the problem is I haven't yet figured out how I make the device realise it must go "out" the direction it is facing.

    Read the article

  • How to test if a string has a certain unicode char?

    - by Ruben Trancoso
    Supose you have a command line executable that receives arguments. This executalbe is widechar ready and you want to test if one of this arguments starts with an HYPHEN case in which its an option: command -o foo how you could test it inside your code if you don't know the charset been used by the host? Should be not possible to a given console to produce the same HYPHEN representation by another char in the widechar forest? (in such case it would be a wild char :P) int _tmain(int argc, _TCHAR* argv[]) { std::wstring inputFile(argv[1]); if(inputFile->c_str() <is an HYPHEN>) { _tprintf(_T("First argument cannot be an option")); } }

    Read the article

  • Can Visual Studio exclude certain folders when searching for header files?

    - by identitycrisisuk
    I'm having trouble with a library that we are using, which has two copies of header files that are needed - one which we are modifying and building from and another which is automatically created during the build process. I don't fully know why or really want to change this but it can cause a bit of annoyance when on random occasions the go to definition function takes you to the auto created header instead of the one used to build. Usually you can spot it but sometimes you don't and make changes to the auto created one, which are then overwritten or sometimes stay around for a while so that something works on your machine but breaks on other peoples. I don't know if there is any way around this as the auto created folder is in the additional include directories of some of the projects in the solution but I just thought I would ask if there was any good way of reducing the chance of this annoying situation cropping up.

    Read the article

< Previous Page | 39 40 41 42 43 44 45 46 47 48 49 50  | Next Page >