random pick string...

how to random pick the string out....when we set the total for string eg:string a = " how to pick out the string"if i choose 3 string out, result: how to pick....or......pick out the....or out the string...
[234 byte] By [shadowssssa] at [2007-10-2 12:09:32]
# 1
Parse the contents into an array of words, then pick a starting point in the array randomly with the range being from (0) to (array length - 3) and print three words from the array starting at that index.Drake
Drake_Duna at 2007-7-13 8:48:45 > top of Java-index,Other Topics,Algorithms...
# 2

Or if it is not consectutive words that you want you could build a one dimensional array, containing the numbers 1-->number of words in sentence, in the corresponding array positions. Then you could shuffle the array and read of the first n elements of the array. The number in each entry represents an index for the array of words and then you can simply get the entry at that index.

eg. simple suffle method, randomly pick an item and move to the end of the array.

static void shuffle(int[] A) {

for (int lastPlace = A.length-1; lastPlace > 0; lastPlace--) {

// Choose a random location from among 0,1,...,lastPlace.

int randLoc = (int)(Math.random()*(lastPlace+1));

// Swap items in locations randLoc and lastPlace.

int temp = A[randLoc];

A[randLoc] = A[lastPlace];

A[lastPlace] = temp;

}

}

hope this helps

the_beea at 2007-7-13 8:48:45 > top of Java-index,Other Topics,Algorithms...