1 34 35 36 package com.micronova.util.codec; 37 38 import java.io.*; 39 import java.util.*; 40 import java.util.zip.*; 41 import com.micronova.util.*; 42 43 public class CodecRandom extends Codec 44 { 45 46 47 public static Object pick(Object object) 48 { 49 if (object != null) 50 { 51 List list = TypeUtil.isList(object); 52 53 if (list != null) 54 { 55 int choiceLength = list.size(); 56 57 if (choiceLength > 0) 58 { 59 int index = (int)(Math.floor(Math.random() * choiceLength)); 60 61 object = list.get(index); 62 } 63 } 64 else 65 { 66 String choice = object.toString(); 67 68 int choiceLength = choice.length(); 69 70 if (choiceLength > 0) 71 { 72 int index = (int)(Math.floor(Math.random() * choiceLength)); 73 74 object = "" + choice.charAt(index); 75 } 76 } 77 } 78 79 return object; 80 } 81 82 83 84 public static Object number(Object object) 85 { 86 if (object != null) 87 { 88 Double max = (Double )CodecType.isDouble(object); 89 90 object = new Double (max.doubleValue() * Math.random()); 91 } 92 93 return object; 94 } 95 } 96 | Popular Tags |