sequence.cpp 731 B

123456789101112131415161718192021222324252627282930313233
  1. /*
  2. * DoRayMe - a quick and dirty Raytracer
  3. * Sequence implementation
  4. *
  5. * Created by Manoël Trapier
  6. * Copyright (c) 2020 986-Studio.
  7. *
  8. */
  9. #include <sequence.h>
  10. #include <stdlib.h>
  11. #include <stdint.h>
  12. #include <time.h>
  13. #include <math_helper.h>
  14. Sequence::Sequence() : list(nullptr), listPos(0), listSize(0) {
  15. /* Need to bootstrap rand here */
  16. srand(time(NULL));
  17. }
  18. Sequence::Sequence(double *list, uint32_t listSize) : list(list), listPos(0), listSize(listSize) { };
  19. double Sequence::next() {
  20. if (this->listSize == 0)
  21. {
  22. return frand();
  23. }
  24. else
  25. {
  26. uint32_t pos = this->listPos;
  27. this->listPos = (this->listPos + 1) % this->listSize;
  28. return this->list[pos];
  29. }
  30. }