Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

SPLIT-UNIQUE - split a block into unique and duplicate values

    split-unique: func [block [any-block!] /local uniq dupe dest] [
        uniq: copy []
        dupe: copy []
        foreach item block [
            dest: either find/only uniq item [dupe] [uniq]
            append/only dest item
        ]
        reduce [uniq dupe]
    ]

C# & Databases - Creating a unique identifer

Creating a new GUID in C# is not as straightforward as one would think. Calling the constructor of System.Guid() will produce a GUID of all zeroes. Using System.Guid.NewGuid() will produce the desired effect of a new, unique identifier.

// produces a "blank" GUID: '00000000-0000-0000-0000-000000000000'
System.Guid blankGuid = new System.Guid(); 

// produces a new, unique GUID: '96d36892-6eed-400c-91f8-a194f3522fae'
System.Guid desiredGuid = System.Guid.NewGuid(); 

unique random array

// 无���机数组

import java.util.Random;
public class Util
{
 private static Random rd = null;
 
  public static int[] random(int[] src)
 {
    if(src == null){
   return null; 
  }
  
  rd = new Random();
   int[] tmp = new int[src.length];
  
  int num = src.length;
  
 
  int index;

  for(int i = 0;i < src.length;i++)
  {
  
   index = Math.abs(rd.nextInt()) % num;
    tmp[i] = src[index];
      src[index] = src[num - 1];
      num--;
  }
  return tmp;
 }
 
 public static void main(String[] args)
 {
  int[] test = {1,2,3,4,5,6,7,8,9};
  int a[] = random(test);
  
  for(int i = 0;i < a.length;i++){
   System.out.println(a[i]); 
  } 
 }
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS