Search Results

Search found 7 results on 1 pages for 'random1'.

Page 1/1 | 1 

  • How to correctly partition usb flash drive and which filesystem to choose considering wear leveling?

    - by random1
    Two problems. First one: how to partition the flash drive? I shouldn't need to do this, but I'm no longer sure if my partition is properly aligned since I was forced to delete and create a new partition table after gparted complained when I tried to format the drive from FAT to ext4. The naive answer would be to say "just use default and everything is going to be alright". However if you read the following links you'll know things are not that simple: https://lwn.net/Articles/428584/ and http://linux-howto-guide.blogspot.com/2009/10/increase-usb-flash-drive-write-speed.html Then there is also the issue of cylinders, heads and sectors. Currently I get this: $sfdisk -l -uM /dev/sdd Disk /dev/sdd: 30147 cylinders, 64 heads, 32 sectors/track Warning: The partition table looks like it was made for C/H/S=*/255/63 (instead of 30147/64/32). For this listing I'll assume that geometry. Units = mebibytes of 1048576 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End MiB #blocks Id System /dev/sdd1 1 30146 30146 30869504 83 Linux $fdisk -l /dev/sdd Disk /dev/sdd: 31.6 GB, 31611420672 bytes 255 heads, 63 sectors/track, 3843 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00010c28 So from my current understanding I should align partitions at 4 MiB (currently it's at 1 MiB). But I still don't know how to set the heads and sectors properly for my device. Second problem: file system. From the benchmarks I saw ext4 provides the best performance, however there is the issue of wear leveling. How can I know that my Transcend JetFlash 700's microcontroller provides for wear leveling? Or will I just be killing my drive faster? I've seen a lot of posts on the web saying don't worry the newer drives already take care of that. But I've never seen a single piece of backed evidence of that and at some point people start mixing SSD with USB flash drives technology. The safe option would be to go for ext2, however a serious of tests that I performed showed horrible performance!!! These values are from a real scenario and not some synthetic test: 42 files: 3,429,415,284 bytes copied to flash drive original fat32: 15.1 MiB/s ext4 after new partition table: 10.2 MiB/s ext2 after new partition table: 1.9 MiB/s Please read the links that I posted above before answering. I would also be interested in answers backed up with some references because a lot is said and re-said but then it lacks facts. Thank you for the help.

    Read the article

  • php -Merging an Array

    - by Vidhu Shresth Bhatnagar
    I have two array which i want to merge in a specific way in php. So i need your help in helping me with it as i tried and failed. So say i have two arrays: $array1= array( "foo" => 3, "bar" => 2, "random1" => 4, ); $array2= array( "random2" => 3, "random3" => 4, "foo" => 6, ); Now when during merging i would like the common key's values to be added. So like foo exists in array1 and in array2 so when merging array1 with array 2 i should get "foo" => "9" I better illustration would be the final array which looks like this: $array1= array( "foo" => 9, "bar" => 2, "random1" => 4, "random2" => 3, "random3" => 4, ); So again i would like the values of the common keys to be added together and non common keys to be added to array or a new array I hope i was clear enough Thanks, Vidhu

    Read the article

  • Example: Controlling randomizer using code contracts

    - by DigiMortal
    One cool addition to Visual Studio 2010 is support for code contracts. Code contracts make sure that all conditions under what method is supposed to run correctly are met. Those who are familiar with unit tests will find code contracts easy to use. In this posting I will show you simple example about static contract checking (example solution is included). To try out code contracts you need at least Visual Studio 2010 Standard Edition. Also you need code contracts package. You can download package from DevLabs Code Contracts page. NB! Speakers, you can use the example solution in your presentations as long as you mention me and this blog in your sessions. Solution has readme.txt file that gives you steps to go through when presenting solution in sessions. This blog posting is companion posting for Visual Studio solution referred below. As an example let’s look at the following class. public class Randomizer {     public static int GetRandomFromRange(int min, int max)     {         var rnd = new Random();         return rnd.Next(min, max);     }       public static int GetRandomFromRangeContracted(int min, int max)     {         Contract.Requires(min < max, "Min must be less than max");           var rnd = new Random();         return rnd.Next(min, max);     } } GetRandomFromRange() method returns results without any checking. GetRandomFromRangeContracted() uses one code contract that makes sure that minimum value is less than maximum value. Now let’s run the following code. class Program {     static void Main(string[] args)     {         var random1 = Randomizer.GetRandomFromRange(0, 9);         Console.WriteLine("Random 1: " + random1);           var random2 = Randomizer.GetRandomFromRange(1, 1);         Console.WriteLine("Random 2: " + random2);           var random3 = Randomizer.GetRandomFromRangeContracted(5, 5);         Console.WriteLine("Random 3: " + random3);           Console.WriteLine(" ");         Console.WriteLine("Press any key to exit ...");         Console.ReadKey();     } } As we have not turned on support for code contracts the code runs without any problems and we get no warnings by Visual Studio that something is wrong. Now let’s turn on static checking for code contracts. As you can see then code still compiles without any errors but Visual Studio warns you about possible problems with contracts. Click on image to see it at original size.  When we open Error list and run our application we get the following output to errors list. Note that these messages are not shown immediately. There is little delay between application starting and appearance of these messages. So wait couple of seconds before going out of your mind. Click on image to see it at original size.  If you look at these warnings you can see that warnings show you illegal calls and also contracts against what they are going. Third warning points to GetRandomFromRange() method and shows that there should be also problem that can be detected by contract. Download Code Contracts example VS2010 solution | 30KB

    Read the article

  • How to generate a cryptographically secure Double between 0 and 1?

    - by Portman
    I know how to generate a random number between 0 and 1 using the NextDouble method of the pseudo-random number generator. var rng1 = new System.Random(); var random1 = rng1.NextDouble(); // generates a random double between 0 and 1.0 And I know how to fill a random byte array using the cryptographically secure random number generator. Byte[] bytes = new Byte[8]; var rng2 = new System.Security.Cryptography.RNGCryptoServiceProvider(); rng2.GetBytes(bytes); // generates 8 random bytes But how can I convert the byte-array output of RNGCryptoServiceProvider into a random number between 0 (inclusive) and 1 (exclusive)?

    Read the article

  • Java Performance measurement

    - by portoalet
    Hi, I am doing some Java performance comparison between my classes, and wondering if there is some sort of Java Performance Framework to make writing performance measurement code easier? I.e, what I am doing now is trying to measure what effect does it have having a method as "synchronized" as in PseudoRandomUsingSynch.nextInt() compared to using an AtomicInteger as my "synchronizer". So I am trying to measure how long it takes to generate random integers using 3 threads accessing a synchronized method looping for say 10000 times. I am sure there is a much better way doing this. Can you please enlighten me? :) public static void main( String [] args ) throws InterruptedException, ExecutionException { PseudoRandomUsingSynch rand1 = new PseudoRandomUsingSynch((int)System.currentTimeMillis()); int n = 3; ExecutorService execService = Executors.newFixedThreadPool(n); long timeBefore = System.currentTimeMillis(); for(int idx=0; idx<100000; ++idx) { Future<Integer> future = execService.submit(rand1); Future<Integer> future1 = execService.submit(rand1); Future<Integer> future2 = execService.submit(rand1); int random1 = future.get(); int random2 = future1.get(); int random3 = future2.get(); } long timeAfter = System.currentTimeMillis(); long elapsed = timeAfter - timeBefore; out.println("elapsed:" + elapsed); } the class public class PseudoRandomUsingSynch implements Callable<Integer> { private int seed; public PseudoRandomUsingSynch(int s) { seed = s; } public synchronized int nextInt(int n) { byte [] s = DonsUtil.intToByteArray(seed); SecureRandom secureRandom = new SecureRandom(s); return ( secureRandom.nextInt() % n ); } @Override public Integer call() throws Exception { return nextInt((int)System.currentTimeMillis()); } } Regards

    Read the article

  • C++ AI Design Question

    - by disney
    Hi, I am currently writing a bot for a MMORPG. Though, currently I am stuck at trying to figure out how to nicely implement this. The design problem is related to casting the character spells in the correct order. Here is a simple example to what I need to archieve. It's not related to casting them, but doing it in the correct order. I would know how simply cast them randomly, by checking which skill has not yet been casted, but in right order as being shown in the GUI, not really. note: the skill amount may differ, it's not always 3, maximum 10 though. Charactername < foobar has 3 skills. Skill 1: Name ( random1 ) cooldown ( 1000 ms ) cast duration ( 500 ms ) Skill 2: Name ( random2 ) cooldown ( 1500 ms ) cast duration ( 700 ms ) Skill 3: Name ( random3 ) cooldown ( 2000 ms ) cast duration ( 900 ms ) I don't really know how I could implement this, if anyone has some thoughts, feel free to share. I do know that most of the people don't like the idea of cheating in games, I don't like it either, nor I am actually playing the game, but its an interesting field for me. Thank you.

    Read the article

1