Search Results

Search found 5712 results on 229 pages for 'j random coder'.

Page 3/229 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Why is it impossible to produce truly random numbers?

    - by Vinoth Kumar
    I was trying to solve a hobby problem that required generating a million random numbers. But I quickly realized, it is becoming difficult to make them unique. I picked up Algorithm Design Manual to read about random number generation. It has the following paragraph that I am fully not able to understand. Unfortunately, generating random numbers looks a lot easier than it really is. Indeed, it is fundamentally impossible to produce truly random numbers on any deterministic device. Von Neumann [Neu63] said it best: “Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.” The best we can hope for are pseudo-random numbers, a stream of numbers that appear as if they were generated randomly. Why is it impossible to produce truly random numbers in any deterministic device? What does this sentence mean?

    Read the article

  • Generating random tunnels

    - by IVlad
    What methods could we use to generate a random tunnel, similar to the one in this classic helicopter game? Other than that it should be smooth and allow you to navigate through it, while looking as natural as possible (not too symmetric but not overly distorted either), it should also: Most importantly - be infinite and allow me to control its thickness in time - make it narrower or wider as I see fit, when I see fit; Ideally, it should be possible to efficiently generate it with smooth curves, not rectangles as in the above game; I should be able to know in advance what its bounds are, so I can detect collisions and generate powerups inside the tunnel; Any other properties that let you have more control over it or offer optimization possibilities are welcome. Note: I'm not asking for which is best or what that game uses, which could spark extended discussion and would be subjective, I'm just asking for some methods that others know about or have used before or even think they might work. That is all, I can take it from there. Also asked on stackoverflow, where someone suggested I should ask here too. I think it fits in both places, since it's as much an algorithm question as it is a gamedev question, IMO.

    Read the article

  • Implementing a Clock Drift random number generator in PHP

    - by Excl
    Hi, I wrote the following code: function create_rand($time) { $counter = 0; $stop = microtime(true) + $time; while(microtime(true) < $stop) $counter++; return $counter; } function create_rand_max($time, $a, $b = false) { $rand_a = create_rand($time); $rand_b = create_rand($time); $rand_c = create_rand($time); $max = max($rand_a, $rand_b, $rand_c); $min = min($rand_a, $rand_b, $rand_c); if($max === $min) return create_rand_max($time, $a, $b); $middle = $rand_a + $rand_b + $rand_c - $max - $min; if($b !== false) return min($a, $b) + ($middle - $min) * (max($a, $b) - min($a, $b)) / ($max - $min); return ($middle - $min) * $a / ($max - $min); } $stop = 1000; $sum = 0; for($i = 0; $i < $stop; $i++) { $sum += create_rand_max(0.001, 100, 200); } echo $sum / $stop; The average is usually between 157 to 161, instead of ~150. Any ideas?

    Read the article

  • How does a cryptographically secure random number generator work?

    - by Byron Whitlock
    I understand how standard random number generators work. But when working with crytpography, the random numbers really have to be random. I know there are instruments that read cosmic white noise to help generate secure hashes, but your standard PC doesn't have this. How does a cryptographically secure random number generator get its values with no repeatable patterns?

    Read the article

  • Random List of numbers in C

    - by Ant
    I have just started a C programming course and so far have only done the basics like printf, read a little on variables etc on the course book. The teacher has tasked us with writing a program that will take a value entered by the user, this will be the number of students in the class (25 at the moment but can be variable). It will then list the number of students randomly and place them in 3 columns. The purpose is to sort students into groups of 3 randomly, then display on the screen in columns. Now my question is not for the code that defeats the object of me attempting the exercise, but how to structure it. I can see that using an array can be used to display the list, but really after some pointers on how best to approach the problem in blocks, then I can attempt to program each block.

    Read the article

  • Does urandom share the same entropy of random?

    - by ???
    Does the entropy pool /dev/random used the same to /dev/urandom? I want to mknod /dev/random 1 9 to replace the slow random, I think the current entropy is randomly enough, if urandom is based on the same entropy, and all succeed random numbers are generated based on that entropy, I don't think there'll be any vulnerable.

    Read the article

  • Arbitrary-precision random numbers in C: generation for Monte Carlo simulation without atmospheric n

    - by Yktula
    I know that there are other questions similar to this one, however the following question pertains to arbitrary-precision random number generation in C for use in Monte Carlo simulation. How can we generate good quality arbitrary-precision random numbers in C, when atmospheric noise isn't always available, without relying on disk i/o or network access that would create bottlenecks? libgmp is capable of generating random numbers, but, like other implementations of pseudo-random number generators, it requires a seed. As the manual mentions, "the system time is quite easy to guess, so if unpredictability is required then it should definitely not be the only source for the seed value." Is there a portable/ported library for generating random numbers, or seeds for random numbers? The libgmp also mentions that "On some systems there's a special device /dev/random which provides random data better suited for use as a seed." However, /dev/random and /dev/urandom can only be used on *nix systems.

    Read the article

  • Python Random Question

    - by coson
    Good Day, I am using Python 2.6 and am trying to run a simple random number generator program (random.py): import random for i in range(5): # random float: 0.0 <= number < 1.0 print random.random(), # random float: 10 <= number < 20 print random.uniform(10, 20), # random integer: 100 <= number <= 1000 print random.randint(100, 1000), # random integer: even numbers in 100 <= number < 1000 print random.randrange(100, 1000, 2) I'm now receiving the following error: C:\Users\Developer\Documents\PythonDemo>python random.py Traceback (most recent call last): File "random.py", line 3, in <module> import random File "C:\Users\Developer\Documents\PythonDemo\random.py", line 8, in <module> print random.random(), TypeError: 'module' object is not callable C:\Users\Developer\Documents\PythonDemo> I've looked at the Python docs and this version of Python supports random. Is there something else I'm missing? TIA, coson

    Read the article

  • Sample uniformly at random from an n-dimensional unit simplex.

    - by dreeves
    Sampling uniformly at random from an n-dimensional unit simplex is the fancy way to say that you want n random numbers such that they are all non-negative, they sum to one, and every possible vector of n non-negative numbers that sum to one are equally likely. In the n=2 case you want to sample uniformly from the segment of the line x+y=1 (ie, y=1-x) that is in the positive quadrant. In the n=3 case you're sampling from the triangle-shaped part of the plane x+y+z=1 that is in the positive octant of R3: (Image from http://en.wikipedia.org/wiki/Simplex.) Note that picking n uniform random numbers and then normalizing them so they sum to one does not work. You end up with a bias towards less extreme numbers. Similarly, picking n-1 uniform random numbers and then taking the nth to be one minus the sum of them also introduces bias. Wikipedia gives two algorithms to do this correctly: http://en.wikipedia.org/wiki/Simplex#Random_sampling (Though the second one currently claims to only be correct in practice, not in theory. I'm hoping to clean that up or clarify it when I understand this better. I initially stuck in a "WARNING: such-and-such paper claims the following is wrong" on that Wikipedia page and someone else turned it into the "works only in practice" caveat.) Finally, the question: What do you consider the best implementation of simplex sampling in Mathematica (preferably with empirical confirmation that it's correct)? Related questions http://stackoverflow.com/questions/2171074/generating-a-probability-distribution http://stackoverflow.com/questions/3007975/java-random-percentages

    Read the article

  • Random number generation in MVC applications

    - by SlimShaggy
    What is the correct way of generating random numbers in an ASP.NET MVC application if I need exactly one number per request? According to MSDN, in order to get randomness of sufficient quality, it is necessary to generate multiple numbers using a single System.Random object, created once. Since a new instance of a controller class is created for each request in MVC, I cannot use a private field initialized in the controller's constructor for the Random object. So in what part of the MVC app should I create and store the Random object? Currently I store it in a static field of the controller class and lazily initialize it in the action method that uses it: public class HomeController : Controller { ... private static Random random; ... public ActionResult Download() { ... if (random == null) random = new Random(); ... } } Since the "random" field can be accessed by multiple instances of the controller class, is it possible for its value to become corrupted if two instances attempt to initialize it simultaneously? And one more question: I know that the lifetime of statics is the lifetime of the application, but in case of an MVC app what is it? Is it from IIS startup till IIS shutdown?

    Read the article

  • C# Random generation

    - by Betamoo
    I have just passed this article online: C# Corner and C# Corner and his article (a software developer with over 13 years of experience) recommended using System.Random as follows: private int RandomNumber(int min, int max) { Random random = new Random(); return random.Next(min, max); } Isn't that would give him the same number every time ?? Edit: So my question will become: How does Random choose its seed? a constant or current time value? Thanks

    Read the article

  • php get, random records, and the back button

    - by Andrew Heath
    My site has a library full of games, nations, game scenarios, etc. library.php is given a type=___ & id=___ for example library.php?type=scenario&id=ABCD001 library.php saves the id to a session variable and loads an include appropriate for the type This all works just dandy. Now, I wanted to give my users the option of pulling up a random scenario. To do that, I added a special id to the logic within lib-scenario.php (the include) such that if given library.php?type=scenario&id=random the include knows to run an alternate query for a random record rather than for the actual id This also works just dandy... unless someone hits the Random Scenario button two+ times in a row, and decides that the previous random scenario was way cooler, I want to go back to that. Because the http address is always directory/library.php?type=scenario&id=random no matter how many times you click Random Scenario, as soon as you click back you'll be taken to the last page with an alternate address you visited. So, if you start at the Home page, and hit Random Scenario 35 times, then decide the 34th one was what you wanted and click BACK, you'll be put back onto the Home page. I must admit this was not a problem I had anticipated. One of my testers was the first to have the urge to back-up in the random scenario stream and here we are. How can I add back-up functionality to my script?

    Read the article

  • Random String Generator creates same string on multiple calls

    - by rockinthesixstring
    Hi there. I've build a random string generator but I'm having a problem whereby if I call the function multiple times say in a Page_Load method, the function returns the same string twice. here's the code ''' <summary>' ''' Generates a Random String' ''' </summary>' ''' <param name="n">number of characters the method should generate</param>' ''' <param name="UseSpecial">should the method include special characters? IE: # ,$, !, etc.</param>' ''' <param name="SpecialOnly">should the method include only the special characters and excludes alpha numeric</param>' ''' <returns>a random string n characters long</returns>' Public Function GenerateRandom(ByVal n As Integer, Optional ByVal UseSpecial As Boolean = True, Optional ByVal SpecialOnly As Boolean = False) As String Dim chars As String() ' a character array to use when generating a random string' Dim ichars As Integer = 74 'number of characters to use out of the chars string' Dim schars As Integer = 0 ' number of characters to skip out of the characters string' chars = { _ "A", "B", "C", "D", "E", "F", _ "G", "H", "I", "J", "K", "L", _ "M", "N", "O", "P", "Q", "R", _ "S", "T", "U", "V", "W", "X", _ "Y", "Z", "0", "1", "2", "3", _ "4", "5", "6", "7", "8", "9", _ "a", "b", "c", "d", "e", "f", _ "g", "h", "i", "j", "k", "l", _ "m", "n", "o", "p", "q", "r", _ "s", "t", "u", "v", "w", "x", _ "y", "z", "!", "@", "#", "$", _ "%", "^", "&", "*", "(", ")", _ "-", "+"} If Not UseSpecial Then ichars = 62 ' only use the alpha numeric characters out of "char"' If SpecialOnly Then schars = 62 : ichars = 74 ' skip the alpha numeric characters out of "char"' Dim rnd As New Random() Dim random As String = String.Empty Dim i As Integer = 0 While i < n random += chars(rnd.[Next](schars, ichars)) System.Math.Max(System.Threading.Interlocked.Increment(i), i - 1) End While rnd = Nothing Return random End Function but if I call something like this Dim str1 As String = GenerateRandom(5) Dim str2 As String = GenerateRandom(5) the response will be something like this g*3Jq g*3Jq and the second time I call it, it will be 3QM0$ 3QM0$ What am I missing? I'd like every random string to be generated as unique.

    Read the article

  • How to insert random characters in a text file at random positions using C

    - by Shantanu Gupta
    I m writing a program to insert random characters in a text file in between the text so that no one can understand this text. eg. suppose this is my text file a.txt with content as "Hi my name is abc. I like to play XYZ" Now i will cal a random function in C and get the 26 modulus random no to get the character to be inserted at random position. eg. "Him mayn mae lkd". etc How can i insert this random character in between the file.

    Read the article

  • How should I use random.jumpahead in Python

    - by Peter Smit
    I have a application that does a certain experiment 1000 times (multi-threaded, so that multiple experiments are done at the same time). Every experiment needs appr. 50.000 random.random() calls. What is the best approach to get this really random. I could copy a random object to every experiment and do than a jumpahead of 50.000 * expid. The documentation suggests that jumpahead(1) already scrambles the state, but is that really true? Or is there another way to do this in 'the best way'? (No, the random numbers are not used for security, but for a metropolis hasting algorithm. The only requirement is that the experiments are independent, not whether the random sequence is somehow predictable or so)

    Read the article

  • Random number within a range based on a normal distribution

    - by ConfusedAgain
    I'm math challenged today :( I want to generate random numbers with a range (n to m, eg 100 to 150), but instead of purely random I want the results to be based on the normal distribution. By this I mean that in general I want the numbers "clustered" around 125. I've found this random number package that seems to have a lot of what I need: http://beta.codeproject.com/KB/recipes/Random.aspx It supports a variety of random generators (include mersiene twister) and can apply the generator to a distribution. But I'm confused... if I use a normal distribution generator the random numbers are from roughly -6 to +8 (apparently the true range is float.min to float.max). How do a scale that to my required range?

    Read the article

  • generate random characters in c

    - by Nick
    I'm new to programming in C and have been given the task of creating a 2D array that stores random letters from A-Z using the random () function. I know how to do random numbers. nextvalue = random ( ) % 10001; but am unsure on how exactly to create a random character. I know that you can use ASCII to create a random character using the range 65 - 90 in the ASCII table. Can anyone help me come up with a solution? I would greatly appreciate it.

    Read the article

  • replace a random word of a string with a random replacement

    - by tpickett
    I am developing a script that takes an article, searches the article for a "keyword" and then randomly replaces that keyword with an anchor link. I have the script working as it should, however I need to be able to have an array of "replacements" for the function to loop through and insert at the random location. So the first random position would get anchor link #1. The second random position would get anchor link #2. The third random position would get anchor link #3. etc... I found half of the answer to my question here: PHP replace a random word of a string public function replace_random ($str, $search, $replace, $n) { // Get all occurences of $search and their offsets within the string $count = preg_match_all('/\b'.preg_quote($search, '/').'\b/', $str, $matches, PREG_OFFSET_CAPTURE); // Get string length information so we can account for replacement strings that are of a different length to the search string $searchLen = strlen($search); $diff = strlen($replace) - $searchLen; $offset = 0; // Loop $n random matches and replace them, if $n < 1 || $n > $count, replace all matches $toReplace = ($n < 1 || $n > $count) ? array_keys($matches[0]) : (array) array_rand($matches[0], $n); foreach ($toReplace as $match) { $str = substr($str, 0, $matches[0][$match][1] + $offset).$replace.substr($str, $matches[0][$match][1] + $searchLen + $offset); $offset += $diff; } return $str; } So my question is, How can i alter this function to accept an array for the $replace variable?

    Read the article

  • C# Random Number Generator getting stuck in a cycle

    - by Jean Azzopardi
    Hi, I am using .NET to create an artificial life program and I am using C#'s pseudo random class defined in a Singleton. The idea is that if I use the same random number generator throughout the application, I could merely save the seed and then reload from the seed to recompute a certain interesting run. public sealed class RandomNumberGenerator : Random { private static readonly RandomNumberGenerator instance = new RandomNumberGenerator(); RandomNumberGenerator() { } public static RandomNumberGenerator Instance { get { return instance; } } } I also wanted a method that could give me two different random numbers. public static Tuple<int, int> TwoDifferentRandomNumbers(this Random rnd, int minValue, int maxValue) { if (minValue >= maxValue) throw new ArgumentOutOfRangeException("maxValue", "maxValue must be greater than minValue"); if (minValue + 1 == maxValue) return Tuple.Create<int, int>(minValue, maxValue); int rnd1 = rnd.Next(minValue, maxValue); int rnd2 = rnd.Next(minValue, maxValue); while (rnd1 == rnd2) { rnd2 = rnd.Next(minValue, maxValue); } return Tuple.Create<int, int>(rnd1, rnd2); } The problem is that sometimes rnd.Next(minValue,maxValuealways returns minValue. If I breakpoint at this point and try creating a double and setting it to rnd.NextDouble(), it returns 0.0. Anyone know why this is happening? I know that it is a pseudo random number generator, but frankly, I hadn't expected it to lock at 0. The random number generator is being accessed from multiple threads... could this be the source of the problem?

    Read the article

  • Generate a random letter in Python

    - by Waterfox
    Is there a way to generate random letters in Python (like random.randint but for letters)? The range functionality of random.randint would be nice but having a generator that just outputs a random letter would be better than nothing.

    Read the article

  • Get a random subset from a set in F#

    - by Cay
    I am trying to think of an elegant way of getting a random subset from a set in F# Any thoughts on this? Perhaps this would work: say we have a set of 2x elements and we need to pick a subset of y elements. Then if we could generate an x sized bit random number that contains exactly y 2n powers we effectively have a random mask with y holes in it. We could keep generating new random numbers until we get the first one satisfying this constraint but is there a better way?

    Read the article

  • Random generates same number in java

    - by user1613360
    This is my java code. import java.io.*; import java.util.*; import java.util.concurrent.TimeUnit; class search { private int numelem; private int[] input=new int[100]; public void setNumofelem() { System.out.println("Enter the total numebr of elements"); Scanner yz=new Scanner(System.in); numelem=yz.nextInt(); } public void randomnumber() throws Exception { int max=500,min=1,n=numelem; Random rand = new Random(); for (int j=0;j < n;j++) { input[j]=rand.nextInt(max)+1; } } public void printinput() { int b=numelem,t=0; while(true) if(b!=0) { System.out.print(" "+input[t]); b--; t++; } else break; } } public class mycode { public static void main(String args[]) throws Exception { search a=new search(); a.setNumofelem(); a.randomnumber(); a.printinput(); } } Now the function randomnumber() just returns the same number.The function executes perfectly if I execute it as a separate java program but fails miserably if I call it using an object.I have also tried the following variations but nothing works everything return the same number. Variation 1: public void randomnumber() throws Exception { int max=500,min=1,n=numelem; Random rand = new Random(); for (int j=0;j < n;j++) { TimeUnit.SECONDS.sleep(1); input[j]=rand.nextInt(max)+1; } } Variation 2: public void randomnumber() throws Exception { int max=500,min=1,n=numelem; Random rand = new Random(); for (int j=0;j < n;j++) { rand.setSeed(System.nanoTime()); input[j]=rand.nextInt(max)+1; } } Variation 3: public void randomnumber() throws Exception { int max=500,min=1,n=numelem; Random rand = new Random(); for (int j=0;j < n;j++) { TimeUnit.SECONDS.sleep(1); rand.setSeed(System.nanoTime()); input[j]=rand.nextInt(max)+1; } } Sample input/Output: Enter the number of elements: 5 23 23 23 23 23 23

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >