diff --git a/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java b/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java index 460e4a6..9595cfd 100644 --- a/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java +++ b/src/main/java/com/ALGo/ALGo_server/quiz/Service/QuizService.java @@ -9,9 +9,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.List; -import java.util.Random; +import java.util.*; @Service @RequiredArgsConstructor @@ -22,14 +20,14 @@ public class QuizService { public QuizResponseDto getQuiz(){ Random random = new Random(); - List quizDtoList = new ArrayList<>(); - for(int i=0;i<4;i++){ + Set quizDtoList = new HashSet<>(); + while (quizDtoList.size() < 4){ Long randomNum = Long.valueOf(random.nextInt(16) + 1); Quiz q = quizRepository.findById(randomNum).get(); QuizDto quizDto = new QuizDto(q); quizDtoList.add(quizDto); } - QuizResponseDto responseDto = new QuizResponseDto(quizDtoList); + QuizResponseDto responseDto = new QuizResponseDto(quizDtoList.stream().toList()); return responseDto; }