;;; init.el -*- lexical-binding: t -*-

(require 'cl-lib)

(defconst syd-features
  '(syd/base
    syd/constants
    syd/dash
    syd/disable-package
    syd/straight
    syd/general
    syd/kanagawa-palette
    syd/on
    syd/prelude
    syd/use-package
    syd/line-numbers
    syd/kanagawa
    syd/comint
    syd/evil
    syd/scrolling
    syd/fonts
    syd/frame
    syd/risky-variables
    syd/completion
    syd/emacs-lisp
    syd/vc
    syd/compilation
    syd/grep
    syd/keymaps
    syd/escape
    syd/leader
    syd/which-key
    syd/tramp
    syd/handle
    syd/org
    syd/org/roam
    syd/org/agenda
    syd/org/latex
    syd/smartparens
    syd/snippets
    syd/ptemplate))

(defun syd-random-permutation (lst &optional seed)
  "Return a random permutation of list LST using SEED as the random state.  The
permutation is deterministic for a given SEED."
  (let* ((random-state (cl-make-random-state (or seed (random))))
         (len (length lst))
         (vec (vconcat lst)))
    ;; Fisher-Yates shuffle.
    (cl-loop for i from (1- len) downto 1 do
             (cl-rotatef (aref vec i)
                         (aref vec (cl-random (1+ i) random-state))))
    ;; Convert vector to list.
    (append vec nil)))

(dolist (feature (syd-random-permutation syd-features
                                         syd-init-load-order-seed))
  (require feature))
