Search Results

Search found 10679 results on 428 pages for 'random numbers'.

Page 8/428 | < Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >

  • Eidetic memory: What magic numbers you still remember?

    - by Hao
    Long before you practice writing readable code, what "magic numbers" you still remember up to this day? here's some of my list: 72 80 75 77 13 32 27 - up down left right enter space escape 1 2 4 128 - blue green red blink 67h 33h 17h - interrupt for EMS, mouse, printer function AH 9, interrupt 21 alt+219 for block ASCII alt+164 ñ 90 NOP 13 10 carriage return, line feed ascii 1 and 2 face, ascii 3 heart. no not this heart: <3 :-) debug -o72,10 -o71,12 clears the BIOS password. I don't know what those numbers mean, it's like a trade secret that gets shared with each other during college days. ascii 7 sounds a beep P.S. Somehow, remembering some of these magic numbers can help you in some tech problems, your keyboard is broken, the office pal's keyboard doesn't have accented characters. An anecdote, during college, one of my friend asked me how to remove the newlines in his Word document. Not having used Word so much then, I somehow "intuitively" guessed to find ^013 and replace it with blank. Well it works :-)

    Read the article

  • Why don't computers store decimal numbers as a second whole number?

    - by SomeKittens
    Computers have trouble storing fractional numbers where the denominator is something other than a solution to 2^x. This is because the first digit after the decimal is worth 1/2, the second 1/4 (or 1/(2^1) and 1/(2^2)) etc. Why deal with all sorts of rounding errors when the computer could have just stored the decimal part of the number as another whole number (which is therefore accurate?) The only thing I can think of is dealing with repeating decimals (in base 10), but there could have been an edge solution to that (like we currently have with infinity).

    Read the article

  • Algorithm to generate N random numbers between A and B which sum up to X

    - by Shaamaan
    This problem seemed like something which should be solvable with but a few lines of code. Unfortunately, once I actually started to write the thing, I've realized it's not as simple as it sounds. What I need is a set of X random numbers, each of which is between A and B and they all add up to X. The exact variables for the problem I'm facing seem to be even simpler: I need 5 numbers, between -1 and 1 (note: these are decimal numbers), which add up to 1. My initial "few lines of code, should be easy" approach was to randomize 4 numbers between -1 and 1 (which is simple enough), and then make the last one 1-(sum of previous numbers). This quickly proved wrong, as the last number could just as well be larger than 1 or smaller than -1. What would be the best way to approach this problem? PS. Just for reference: I'm using C#, but I don't think it matters. I'm actually having trouble creating a good enough solution for the problem in my head.

    Read the article

  • Help for creating a random String

    - by Max
    I need to create a random string which should be between the length of 6 to 10 but it sometimes generates only about the length of 3 to 5. Here's my code. Can anyone would be able to find out the problem? :( int lengthOfName = (int)(Math.random() * 4) + 6; String name = ""; /* randomly choosing a name*/ for (int j = 0; j <= lengthOfName; j++) { int freq = (int)(Math.random() * 100) + 1; if(freq <= 6){ name += "a"; }if(freq == 7 && freq == 8){ name += "b"; }if(freq >= 9 && freq <= 11){ name += "c"; }if(freq >= 12 && freq <= 15){ name += "d"; }if(freq >= 16 && freq <= 25){ name += "e"; }if(freq == 26 && freq == 27){ name += "f"; }if(freq == 28 && freq == 29){ name += "g"; }if(freq >= 30 && freq <= 33){ name += "h"; }if(freq >= 34 && freq <= 48){ name += "i"; }if(freq == 49 && freq == 50){ name += "j"; }if(freq >= 51 && freq <= 55){ name += "k"; }if(freq >= 56 && freq <= 60){ name += "l"; }if(freq == 61 && freq == 62){ name += "m"; }if(freq >= 63 && freq <= 70){ name += "n"; }if(freq >= 71 && freq <= 75){ name += "o"; }if(freq == 76 && freq == 77){ name += "p"; }if(freq == 78){ name += "q"; }if(freq >= 79 && freq <= 84){ name += "r"; }if(freq == 85 && freq == 86){ name += "s"; }if(freq == 87 && freq == 88){ name += "t"; }if(freq >= 89 && freq <= 93){ name += "u"; }if(freq == 94){ name += "v"; }if(freq == 95 && freq == 96){ name += "w"; }if(freq == 97){ name += "x"; }if(freq == 98 && freq == 99){ name += "y"; }if(freq == 100){ name += "z"; } }

    Read the article

  • Get special numbers from a random number generator

    - by Wikeno
    I have a random number generator: int32_t ksp_random_table[GENERATOR_DEG] = { -1726662223, 379960547, 1735697613, 1040273694, 1313901226, 1627687941, -179304937, -2073333483, 1780058412, -1989503057, -615974602, 344556628, 939512070, -1249116260, 1507946756, -812545463, 154635395, 1388815473, -1926676823, 525320961, -1009028674, 968117788, -123449607, 1284210865, 435012392, -2017506339, -911064859, -370259173, 1132637927, 1398500161, -205601318, }; int front_pointer=3, rear_pointer=0; int32_t ksp_rand() { int32_t result; ksp_random_table[ front_pointer ] += ksp_random_table[ rear_pointer ]; result = ( ksp_random_table[ front_pointer ] >> 1 ) & 0x7fffffff; front_pointer++, rear_pointer++; if (front_pointer >= GENERATOR_DEG) front_pointer = 0; if (rear_pointer >= GENERATOR_DEG) rear_pointer = 0; return result; } void ksp_srand(unsigned int seed) { int32_t i, dst=0, kc=GENERATOR_DEG, word, hi, lo; word = ksp_random_table[0] = (seed==0) ? 1 : seed; for (i = 1; i < kc; ++i) { hi = word / 127773, lo = word % 127773; word = 16807 * lo - 2836 * hi; if (word < 0) word += 2147483647; ksp_random_table[++dst] = word; } front_pointer=3, rear_pointer=0; kc *= 10; while (--kc >= 0) ksp_rand(); } I'd like know what type of pseudo random number generation algorithm this is. My guess is a multiple linear congruential generator. And is there a way of seeding this algorithm so that after 987721(1043*947) numbers it would return 15 either even-only, odd-only or alternating odd and even numbers? It is a part of an assignment for a long term competition and i've got no idea how to solve it. I don't want the final solution, I'd like to learn how to do it myself.

    Read the article

  • Is this a correct porting of java.util.Random in objectiveC

    - by dipu
    I have ported the code inside java.util.Random class in objectivec. I want to have an identical random number generator so that it synchs with the server app running on java. Now is this a safe porting and if not is there a way to mimic AtomicLong as it is found in java? Please see my code below. static long long multiplier = 0x5DEECE66DL; static long addend = 0xBL; static long long mask = (0x1000000000000001L << 48) - 1; -(void) initWithSeed:(long long) seed1 { [self setRandomSeed: 0L];// = new AtomicLong(0L); [self setSeed: seed1]; } -(int) next:(int)bits { long long oldseed, nextseed; long long seed1 = [self.randomSeed longLongValue]; //AtomicLong //do { oldseed = seed1; nextseed = (oldseed * multiplier + addend) & mask; //} while (!seed.compareAndSet(oldseed, nextseed)); [self setRandomSeed: [NSNumber numberWithLongLong:nextseed]]; ///int ret = (int)(nextseed >>> (48 - bits)); int ret = (unsigned int)(nextseed >> (48 - bits)); return ret; } -(void) setSeed:(long long) seed1 { seed1 = (seed1 ^ multiplier) & mask; [self setRandomSeed: [NSNumber numberWithLongLong:seed1]]; }

    Read the article

  • Smarty multiple random numbers list

    - by Heinrich
    Hey Stackoverflow-Folks, is there any smart way to post random numbers (e.g. 1-4) in a list by using the smarty tpl-engine? standart list sorted 1-5: <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> </ul> Here's my solution (PHP): <ul> {foreach from=randomNumbers} <li>{smarty.randomNumbers}</li> {/foreach} </ul> modified list sorted 1-5 (random): <ul> <li>3</li> <li>2</li> <li>5</li> <li>1</li> <li>4</li> </ul> I've really tested nearly everything, but I do only need a smart & small solution for this :-) Kind Regards, Heinrich

    Read the article

  • Best way to get a random number from 1 to 50 which ISN'T x

    - by Cocorico
    Hi guys! So this is probably programming 101 stuff, but I have a problem: I have 2 numbers which are between 0 and 49. Let's call them x and y. Now I want to get a couple of other numbers which are not x or y, but are also between 0 and 49 (I am using Objective C but this is more of a general theory question I think?). Method I thought of is: int a; int b; int c; do { a = arc4random() % 49; } while ((a == x) || (a == y)); do { b = arc4random() % 49; } while ((b == x) || (b == y) || (b == a)); do { c = arc4random() % 49; } while ((c == x) || (c == y) || (c == a) || (c == b)); But it seem kind of bad to me, I don't know, I am just trying to learn to be a better programmer, what would be the most elegant sweet way to do this for best practices? Thanks!

    Read the article

  • Random problem connecting to MySQL

    - by CharlesLeaf
    Environment: RHEL 5 servers, MySQL 5.1.43, PHP 5.1.6 (using MySQLi). Currently only available within our internal VPN network. Servers ServerA: Webserver ServerB/C/D: Database server (1 master 2 slaves) The error (on ServerA) [Tue May 25 11:12:17 2010] [error] [client CLIENTIP] PHP Warning: mysqli::real_connect() [function.mysqli-real-connect]: (HY000/2003): Can't connect to MySQL server on 'ServerB' (4) in /home/**/Database.php on line 67, referer: [website] Problem description It appears that at completely random times, our website is unable to connect to one of the MySQL servers - usually the Master. Except for the forementioned error message, there is nothing to be found in any of the logs as far as I can see, and most of the times the connection is succesful and everything works as it should. It's just at completely random times, this error pops up. There's no firewall blocking any internal traffic, timeout value is 3 but it doesn't take 3 seconds before it fails to connect. With the default mysql client I can connect from ServerA to ServerB,C and D and haven't encountered a problem yet. Does anyone have a clue what I might be overlooking / could be the problem? Because I've run out of ideas myself.

    Read the article

  • Random Movement in a Fixed Container

    - by James Barracca
    I'm looking to create something that can move randomly inside of a fixed div container. I love the way the object moves in this example that I found searching this website... http://jsfiddle.net/Xw29r/15/ The code on the jsfiddle contains the following: $(document).ready(function(){ animateDiv(); }); function makeNewPosition(){ // Get viewport dimensions (remove the dimension of the div) var h = $(window).height() - 50; var w = $(window).width() - 50; var nh = Math.floor(Math.random() * h); var nw = Math.floor(Math.random() * w); return [nh,nw]; } function animateDiv(){ var newq = makeNewPosition(); var oldq = $('.a').offset(); var speed = calcSpeed([oldq.top, oldq.left], newq); $('.a').animate({ top: newq[0], left: newq[1] }, speed, function(){ animateDiv(); }); }; function calcSpeed(prev, next) { var x = Math.abs(prev[1] - next[1]); var y = Math.abs(prev[0] - next[0]); var greatest = x > y ? x : y; var speedModifier = 0.1; var speed = Math.ceil(greatest/speedModifier); return speed; }? CSS: div.a { width: 50px; height:50px; background-color:red; position:fixed; }? However, I don't believe the code above constricts that object at all. I need my object to move randomly inside of a container that is let's say for now... 1200px in width and 500px in height. Can someone steer me in the right direction? I'm super new to coding so I'm having a hard time finding an answer on my own. Thanks so much! James

    Read the article

  • letters or numbers only in a password with jquery

    - by Greg
    Hi, I found this code for alphanumeric check ("Letters, numbers, spaces or underscores") but I want to change so I will be able to write only letters or numbers. Can anyone tell me how to change this code: function(value, element) { return this.optional(element) || /^\w+$/i.test(value);} Thanks! Greg

    Read the article

  • Big numbers in C

    - by teehoo
    I need help working with very big numbers. According to Windows calc, the exponent 174^55 = 1.6990597648061509725749329578093e+123. How would I store this using C (c99 standard). int main(){ long long int x = 174^55; //result is 153 printf("%lld\n", x); } For those curious, it is for a school project where we are implementing the RSA cryptographic algorithm, which deals with exponentiating large numbers with large powers for encryption/decryption.

    Read the article

  • Problem in displaying numbers in Flex AdvancedDataGrid

    - by user211607
    Hi, I am able to display any data (numbers) in Flex AdvancedDataGrid except data with lot of digits after decimal places (0.000000000029103830456733704) or exponential numbers (293E-17). Grid is displaying -17 instead of 293E-17. Is it happening because of any limit to displaying data range in grid? If yes, what is the limit? Thanks in advance ... Atul

    Read the article

  • Converting numbers to their language, how?

    - by SoLoGHoST
    Ok, I'm using mathematical equations to output numbers, though, I need this to be compatible for all languages. Currently, all language strings are within a php array called $txt, and each key of the array gets called for that language. I'm outputting the following: Column 1, Column 2, Column 3, and so on, as well as Row 1, Row 2, Row 3, and so on. The calculations are done via php and javascript, so I'm wondering on the best approach for how to support all languages for the numbers only. I don't do the translations, someone else does, but I need to be able to point it to, either the php variable $txt of where the language is defined, or, since the calculations are done via javascript also, I need to somehow store this in there. I'm thinking of storing something like this: // This part goes in the php language file. $txt['0'] = '0'; $txt['1'] = '1'; $txt['2'] = '2'; $txt['2'] = '3'; $txt['4'] = '4'; $txt['5'] = '5'; $txt['6'] = '6'; $txt['7'] = '7'; $txt['8'] = '8'; $txt['9'] = '9'; // This part goes in the php file that needs to call the numbers. echo '<script> var numtxts = new Array(); numtxts[0] = \'', $txt['0'], '\'; numtxts[1] = \'', $txt['1'], '\'; numtxts[2] = \'', $txt['2'], '\'; numtxts[3] = \'', $txt['3'], '\'; numtxts[4] = \'', $txt['4'], '\'; numtxts[5] = \'', $txt['5'], '\'; numtxts[6] = \'', $txt['6'], '\'; numtxts[7] = \'', $txt['7'], '\'; numtxts[8] = \'', $txt['8'], '\'; numtxts[9] = \'', $txt['9'], '\'; </script>'; And than in the javascript function it could grab the correct string for each number like so: // Example Number String below. var numString = "10"; var transNum = ""; for(x=0;x<numString.length;x++) { var numChar = numString.charAt(x); transNum += numtxts[parseInt(numChar)]; } return transNum; The problem with this bit of code is that it groups the numbers, not sure if all languages do that, like the english language does...? Perhaps there's a better approach for this? Can anyone help please? Thanks :)

    Read the article

  • Trying to grab several random videos from database, but it just shows the same one all the time.

    - by Birk
    Hi guys, I'm trying to grab several random videos from my database, and have them show on a page. However, it just keeps on grabbing the same video rather than several different ones. So I end up with 5 of the same video rather than 5 different ones. Here's the grab random PHP code file... and after it is the template output file. //===================================================== // Random | Previous | Next //===================================================== $show['random'] = $db->quick_fetch( "SELECT file_id, title, title_seo, category_id, thumb FROM files WHERE files.category_id = '".$show['main']['category_id']."' AND files.verified=1 ORDER BY RAND() LIMIT 0,1; "); Here's the template CSS html thingy code I have this pasted 5 times to show 5 random videos <td valign="top" width="53%"><? $sql="select * from files ORDER BY rand() limit 0,5"; $res=@mysql_query($sql); $data=@mysql_result($res,0,'filename'); $id=@mysql_result($res,0,'file_id'); $title=@mysql_result($res,0,'title'); $title2=str_replace(" ", "-",$title); $path="{$siteurl}/media/{$file.random.file_id}/{$file.random.title_seo}/"; $img="{$siteurl}/thumbs/{$file.random.thumb}"; echo " {$file.random.title}"

    Read the article

  • Using a random string to authenticate HMAC?

    - by mrwooster
    I am designing a simple webservice and want to use HMAC for authentication to the service. For the purpose of this question we have: a web service at example.com a secret key shared between a user and the server [K] a consumer ID which is known to the user and the server (but is not necessarily secret) [D] a message which we wish to send to the server [M] The standard HMAC implementation would involve using the secret key [K] and the message [M] to create the hash [H], but I am running into issues with this. The message [M] can be quite long and tends to be read from a file. I have found its very difficult to produce a correct hash consistently across multiple operating systems and programming languages because of hidden characters which make it into various file formats. This is of course bad implementation on the client side (100%), but I would like this webservice to be easily accessible and not have trouble with different file formats. I was thinking of an alternative, which would allow the use a short (5-10 char) random string [R] rather than the message for autentication, e.g. H = HMAC(K,R) The user then passes the random string to the server and the server checks the HMAC server side (using random string + shared secret). As far as I can see, this produces the following issues: There is no message integrity - this is ok message integrity is not important for this service A user could re-use the hash with a different message - I can see 2 ways around this Combine the random string with a timestamp so the hash is only valid for a set period of time Only allow each random string to be used once Since the client is in control of the random string, it is easier to look for collisions I should point out that the principle reason for authentication is to implement rate limiting on the API service. There is zero need for message integrity, and its not a big deal if someone can forge a single request (but it is if they can forge a very large number very quickly). I know that the correct answer is to make sure the message [M] is the same on all platforms/languages before hashing it. But, taking that out of the equation, is the above proposal an acceptable 2nd best?

    Read the article

  • Generate a random alphanumeric string in cocoa

    - by Ward
    Hey there, I know this can't be that hard. I've searched, but I can't seem to find a simple solution. I want to call a method, pass it the length and have it generate a random alphanumeric string. Any ideas? Are there any utility libraries out there that may have a bunch of these types of functions? Thanks, Howie

    Read the article

  • Random numbers from -10 to 10 in C++

    - by Chris_45
    How does one make random numbers in the interval -10 to 10 in C++ ? srand(int(time(0)));//seed for(int i = 0; i < size; i++){ myArray[i] = 1 + rand() % 20 - 10;//this will give from -9 to 10 myArray2[i] =rand() % 20 - 10;//and this will -10 to 9 }

    Read the article

< Previous Page | 4 5 6 7 8 9 10 11 12 13 14 15  | Next Page >