package services;

import java.util.List;
import java.util.Random;

import models.Esquema;
import models.Palabra;
import enums.Numero;

public class RandomService {
	private static RandomService instance;

	public static RandomService getInstance() {
		if (instance == null)
			instance = new RandomService();
		return instance;
	}

	private RandomService() {

	}

	public Esquema randomEsquema() {
		EsquemaService es = EsquemaService.getInstance();
		List<Esquema> esq = es.getEsquemas();
		return esq.get(new Random().nextInt(esq.size()));
	}

	public Palabra randomPalabra(List<? extends Palabra> arr, Numero numero) {
		Palabra result = null;
		do {
			result = arr.get(new Random().nextInt(arr.size()));
		} while (result.getNumero() != numero && numero != null);
		return result;
	}

}

@@ -59,16 +59,52 @@
 .Random;
+%0Aimport java.util.stream.Collectors;
 %0A%0Aimport
@@ -656,112 +656,107 @@
 ) %7B%0A
+%0A
 %09%09
-Palabra result 
+List%3C? extends Palabra%3E aux = arr;%0A%09%09if (numero !
 = null
-;
+)
 %0A%09%09
-do 
 %7B%0A%09%09%09
-result
+ aux
  = arr.
-get(new Random().nextInt(arr.size()));%0A%09%09%7D while (result
+stream().filter(x-%3E x
 .get
@@ -768,17 +768,17 @@
 o() 
-!
+=
 = numero
  && 
@@ -777,44 +777,95 @@
 mero
- && numero != null);%0A%09%09return result
+).collect(Collectors.toList());;%0A%09%09%7D%0A%09%09return aux.get(new Random().nextInt(aux.size()))
 ;%0A%09%7D

mejora en metodo de random, ahora uso lambda para filtrar la lista antes de hacerlo. Se saco el while