Search Results

Search found 5163 results on 207 pages for 'random'.

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

  • Fastest Way to generate 1,000,000+ random numbers in python

    - by Sandro
    I am currently writing an app in python that needs to generate large amount of random numbers, FAST. Currently I have a scheme going that uses numpy to generate all of the numbers in a giant batch (about ~500,000 at a time). While this seems to be faster than python's implementation. I still need it to go faster. Any ideas? I'm open to writing it in C and embedding it in the program or doing w/e it takes. Constraints on the random numbers: A Set of numbers 7 numbers that can all have different bounds: eg: [0-X1, 0-X2, 0-X3, 0-X4, 0-X5, 0-X6, 0-X7] Currently I am generating a list of 7 numbers with random values from [0-1) then multiplying by [X1..X7] A Set of 13 numbers that all add up to 1 Currently just generating 13 numbers then dividing by their sum Any ideas? Would pre calculating these numbers and storing them in a file make this faster? Thanks!

    Read the article

  • Using system time directly to get random numbers

    - by Richard Mar.
    I had to return a random element from an array so I came up with this placeholder: return codes[(int) (System.currentTimeMillis() % codes.length - 1)]; Now than I think of it, I'm tempted to use it in real code. The Random() seeder uses system time as seed in most languages anyway, so why not use that time directly? As a bonus, I'm free from the worry of non-random lower bits of many RNGs. It this hack coming back to bite me? (The language is Java if that's relevant.)

    Read the article

  • Random enemy placement on a 2d grid

    - by Robb
    I want to place my items and enemies randomly (or as randomly as possible). At the moment I use XNA's Random class to generate a number between 800 for X and 600 for Y. It feels like enemies spawn more towards the top of the map than in the middle or bottom. I do not seed the generator, maybe that is something to consider. Are there other techniques described that can improve random enemy placement on a 2d grid?

    Read the article

  • Biased Random Number Generator

    - by cmptrer
    I am looking for a random number generator that can be biased. For instance, say I want a random number between 1-5, with the probability being: 1: Comes up 20% of the time 2: Comes up 10% of the time 3: Comes up 40% of the time 4: Comes up 25% of the time 5: Comes up 5% of the time Is there anything in the standard library, or other libraries out there that would do this? Alternatively, is there an efficient way to do this myself?

    Read the article

  • Getting N random numbers that the sum is M

    - by marionmaiden
    Hello I want to get N random numbers that the sum of them is a value. For example, let's suppose I want 5 random numbers that their sum is 1 Then, a valid possibility is: 0.2 0.2 0.2 0.2 0.2 Other possibility is: 0.8 0.1 0.03 0.03 0.04 And so on. I need this for the creation of the matrix of belongings of the Fuzzy C-means.

    Read the article

  • Random World Generation

    - by Alex Larsen
    I'm making a game like minecraft (although a different idea) but I need a random world generator for a 1024 block wide and 256 block tall map. Basically so far I have a multidimensional array for each layer of blocks (a total of 262,114 blocks). This is the code I have now: Block[,] BlocksInMap = new Block[1024, 256]; public bool IsWorldGenerated = false; Random r = new Random(); private void RunThread() { for (int BH = 0; BH <= 256; BH++) { for (int BW = 0; BW <= 1024; BW++) { Block b = new Block(); if (BH >= 192) { } BlocksInMap[BW, BH] = b; } } IsWorldGenerated = true; } public void GenWorld() { new Thread(new ThreadStart(RunThread)).Start(); } I want to make tunnels and water but the way blocks are set is like this: Block MyBlock = new Block(); MyBlock.BlockType = Block.BlockTypes.Air; How would I manage to connect blocks so the land is not a bunch of floating dirt and stone?

    Read the article

  • SQLAuthority News – Random Thoughts and Random Ideas

    - by pinaldave
    There are days when I keep on wondering about SQL, and even my life overall. Today is Saturday so I decided to write about SQL Server. Just like any other mornings, I woke up at 5 and opened my blog editor. I usually do not open Twitter or Facebook when I am planning to focus on my work, as they are little distractions for me. But today I opened my Twitter account and came across a very interesting quote from a friend: ‘Can I expect you to be different today?’ Well, I think it was very powerful quote for me to read first thing on a new day. This quote froze me for a while and made me think, “Do I really want to write about an SQL Server tip, or something different?”  After a little thinking, I’ve realized that for today I would go on and write something different. I am going to write about a few of the ideas and thoughts I had yesterday. After writing all these, I realized that if I am thinking so much in a day, and if I write a blog post of my random musing of the week or month, it can be so long (and boring). Here are some of my random thoughts I’d like to share with you: When the airplane lands, why does everybody get up and try to rush out when their luggage would be coming probably 20-30 minutes later? I really do not like this question when it was asked to me: “SQL Server is not using optimal index which I just created – how can I force it?” I am not going elaborate on this statement but you are allowed to in the comment section. Why do some people wish Good Morning even when they meet us after 4 PM? Can I optimize a query so much that it gives me a result before I execute it? Is it corruption when someone does their personal household work at office? The lane where I drive is always the slowest lane. Why waste time on correcting others when there are a lot of pending improvements for ourselves? If I have to get Tattoo, which SQL Server Execution Plan symbol should I get? Why do I reach office so early that the coffee machine is yet running its daily cleaning job? Why does every laptop have a ‘Page Up’ key at different locations on the keyboard? While I like color movies, I really appreciate black and white photographs. I do not appreciate statements like, “If I receive your books in PDF, I will spread it to many people to give you much greater exposure. So would you please send them to me ASAP?” Do not tell me, “Why does the database grow back after shrinking it every day?” I suggest you use “Search this blog” for the explanation. Petrol prices are currently at INR 74. I hope the rate remains there. Let me ask you the same question which started my day today:  “Can I expect you to be different today?” Reference: Pinal Dave (http://blog.SQLAuthority.com) Filed under: About Me, PostADay, SQL, SQL Authority, SQL Query, SQL Server, SQL Tips and Tricks, T SQL, Technology

    Read the article

  • Python: Random is barely random at all?

    - by orokusaki
    I did this to test the randomness of randint: >>> from random import randint >>> >>> uniques = [] >>> for i in range(4500): # You can see I optimistic. ... x = randint(500, 5000) ... if x in uniques: ... raise Exception('We duped ' + str(x) + ' at iteration number ' + str(i)) ... uniques.append(x) ... Traceback (most recent call last): File "(stdin)", line 4, in (module) Exception: 'We duped 4061 at iteration number 67 I tried about 10 times more and the best result I got was 121 iterations before a repeater. Is this the best sort of result you can get from the standard library?

    Read the article

  • Random number generation

    - by Chandan Shetty SP
    I am using below code to generate random numbers in range... int randomNumberWithinRange(int min,int max) { int snowSize = 0; do { snowSize = rand()%max; } while( snowSize < min || snowSize > max ); return snowSize; } for(int i = 0; i < 10 ; i++) NSlog("@"%d",\t", randomNumberWithinRange(1,100)); If I quit my application and restart, same set of numbers are generated. How to generate different set of random numbers for every launching.

    Read the article

  • Probability Random Number Generator

    - by Excl
    Let's say I'm writing a simple luck game - each player presses Enter and the game assign him a random number between 1-6. Just like a cube. At the end of the game, the player with the highest number wins. Now, let's say I'm a cheater. I want to write the game so player #1 (which will be me) has a probability of 90% to get six, and 2% to get each of the rest numbers (1, 2, 3, 4, 5). So, how can I generate a number random, and set the probability for each number? Thanks.

    Read the article

  • Use of qsrand, random method that is not random

    - by Andy M
    Hey everyone, I'm having a strange problem here, and I can't manage to find a good explanation to it, so I thought of asking you guys : Consider the following method : int MathUtility::randomize(int Min, int Max) { qsrand(QTime::currentTime().msec()); if (Min > Max) { int Temp = Min; Min = Max; Max = Temp; } return ((rand()%(Max-Min+1))+Min); } I won't explain you gurus what this method actually does, I'll instead explain my problem : I realised that when I call this method in a loop, sometimes, I get the same random number over and over again... For example, this snippet... for(int i=0; i<10; ++i) { int Index = MathUtility::randomize(0, 1000); qDebug() << Index; } ...will produce something like : 567 567 567 567...etc... I realised too, that if I don't call qsrand everytime, but only once during my application's lifetime, it's working perfectly... My question : Why ?

    Read the article

  • Difference Procedural Generation and Random Generation

    - by U-No-Poo
    Today, I got into an argument about the term "procedural generation". My point was that its different from "classic" random generation in the way that procedural is based on a more mathematical, fractal based, algorithm leading to a more "realistic" distribution and the usual randomness of most languages are based on a pseudo-random-number generator, leading to an "unrealistic", in a way, ugly, distribution. This discussion was made with a heightmap in mind. The discussion left me somehow unconvinced about my own arguments though, so, is there more to it? Or am I the one who is, in fact, simply wrong?

    Read the article

  • Random number generation algorithm for human brains?

    - by Magnus Wolffelt
    Are you aware of, or have you devised, any practical, simple-to-learn "in-head" algorithms that let humans generate (somewhat "true") random numbers? By "in-head" I mean.. preferrably without any external tools or devices. Also, a high output (many random numbers per minute) is desirable. Asked this on SO but it didn't get much interest. Maybe this is better suited for programmers.. :) I'm genuinely curious about anything that people might have come up with on this problem.

    Read the article

  • Random Cache Expiry

    - by mahemoff
    I've been experimenting with random cache expiry times to avoid situations where an individual request forces multiple things to update at once. For example, a web page might include five different components. If each is set to time out in 30 minutes, the user will have a long wait time every 30 minutes. So instead, you set them all to a random time between 15 and 45 minutes to make it likely at most only one component will reload for any given page load. I'm trying to find any research or guidelines on this topic, e.g. optimal variance parameters. I do recall seeing one article about how Google (?) uses this technique, but can't locate it, and there doesn't seem to be much written about the topic.

    Read the article

  • VB.NET - Removing a number from a random number generator

    - by Alex
    I am trying to create a lottery simulator. The lottery has 6 numbers, the number generated must be between 1 - 49 and cannot be in the next number generated. I have tried using the OR function but I'm not entirely sure if I am using it properly. Any help would be great. Thanks. Public Class Form1 Private Sub cmdRun_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRun.Click 'Creates a new Random class in VB.NET Dim RandomClass As New Random() '#################################### Dim RandomNumber1 As Integer RandomNumber1 = RandomClass.Next(1, 49) 'Displays first number generated txtFirst.Text = (RandomNumber1) '#################################### Dim RandomNumber2 As Integer RandomNumber2 = RandomClass.Next(1, 49) If RandomNumber2 = RandomNumber1 Then RandomNumber2 = RandomClass.Next(1, 49) End If 'Displays second number generated txtSecond.Text = (RandomNumber2) '#################################### Dim RandomNumber3 As Integer RandomNumber3 = RandomClass.Next(1, 49) If RandomNumber3 = RandomNumber2 Or RandomNumber2 Then RandomNumber3 = RandomClass.Next(1, 49) End If 'Displays third number generated txtThird.Text = (RandomNumber3) '#################################### Dim RandomNumber4 As Integer RandomNumber4 = RandomClass.Next(1, 49) If RandomNumber4 = RandomNumber3 Or RandomNumber2 Or RandomNumber1 Then RandomNumber4 = RandomClass.Next(1, 49) End If 'Displays fourth number generated txtFourth.Text = (RandomNumber4) '#################################### Dim RandomNumber5 As Integer RandomNumber5 = RandomClass.Next(1, 49) If RandomNumber5 = RandomNumber4 Or RandomNumber3 Or RandomNumber2 Or RandomNumber1 Then RandomNumber5 = RandomClass.Next(1, 49) End If 'Displays fifth number generated txtFifth.Text = (RandomNumber5) '#################################### Dim RandomNumber6 As Integer RandomNumber6 = RandomClass.Next(1, 49) If RandomNumber6 = RandomNumber5, RandomNumber4, RandomNumber3, RandomNumber2, RandomNumber1 Then RandomNumber6 = RandomClass.Next(1, 49) End If 'Displays sixth number generated txtSixth.Text = (RandomNumber6) End Sub

    Read the article

  • C++ random number from a set

    - by user69514
    Is it possible to print a random number in C++ from a set of numbers with ONE SINGLE statement? let's say the set is 2, 5, 22, 55, 332 i looked up rand, but I double it's possible to do in a single statement

    Read the article

  • How do I produce "enjoyably" random, as opposed to pseudo-random?

    - by Hilton Campbell
    I'm making a game which presents a number of different kinds of puzzles in sequence. I choose each puzzle with a pseudorandom number. For each puzzle, there are a number of variations. I choose the variation with another pseudorandom number. And so on. The thing is, while this produces near-true randomness, this isn't what the player really wants. The player typically wants what they perceive to be and identify as random, but only if it doesn't tend to repeat puzzles. So, not really random. Just unpredictable. Giving it some thought, I can imagine hacky ways of doing it. For example, temporarily eliminating the most recent N choices from the set of possibilities when selecting a new choice. Or assigning every choice an equal probability, reducing a choice's probability to zero on selection, and then increasing all probabilities slowly with each selection. I assume there's an established way of doing this, but I just don't know the terminology so I can't find it. Anyone know? Or has anyone solved this in a pleasing way?

    Read the article

  • Random generation of interesting puzzle levels?

    - by monsterfarm
    I'm making a Sokoban-like game i.e. there's a grid that has some crates on it you can push and you have to get the crates on crosses to win the level (although I'm going to add some extra elements to it). Are there any general algorithms or reading material I can look at for how I could go about generating interesting (as in, not trivial to solve) levels for this style of game? I'm aware that random level generators exist for Sokoban but I'm having trouble finding the algorithm descriptions. I'm interested in making a game where the machine can generate lots of levels for me, sorted by difficulty. I'm even willing to constrain the rules of the game to make the level generation easier (e.g. I'll probably limit the grid size to about 7x7). I suspect there are some general ways to do level generation here as I've seen e.g. Traffic Jam-like games (where you have to move blocks around the free some block) with 1000s of levels where each one has a unique solution. One idea I had was to generate a random map in its final state (i.e. where all crates are on top of their crosses) and then the computer would pull (instead of push) these crates around to create a level. The nice property here is that we know the level is solvable. However, I'd need some heuristics to ensure the level was interesting.

    Read the article

  • is Microsoft LC random generator patented?

    - by user396672
    I need a very simple pseudo random generator (no any specific quality requirements) and I found Microsoft's variant of LCG algorithm used for rand() C runtime library function fit my needs (gcc's one seems too complex). I found the algorithm here: http://rosettacode.org/wiki/Linear_congruential_generator#C However, I worry the algorithm (including its "magic numbers" i.e coefficients) may by patented or restricted for use in some another way. Is it allowed to use this algorithm without any licence or patent restrictions or not? I can't use library rand() because I need my results to be exactly reproducible on different platforms

    Read the article

  • Random Position between ranges.

    - by blakey87
    Does anyone have a good algorithm for generating a random y position for spawning a block, which takes into account a minimum and maximum height, allowing player to to jump on the block. Blocks will continually be spawned, so the player must always be able to jump onto the next block, bearing in mind the minimum position which would be the ground, and the maximum which would the players jump height bearing in mind the ceiling

    Read the article

  • Best way to choose random element from weighted list

    - by Qqwy
    I want to create a simple game. Every so often, a power up should appear. Right now the different kinds of power ups are stored in an array. However, not every power up should appear equally often: For instance, a score multiplier should appear much more often than an extra life. What is the best/fastest way to pick an element at random from a list where some of the elements should be picked more often than others?

    Read the article

  • 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

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