package roommgr

import (
	"math/rand"
	"time"
)

var roomids = make([]uint32, 0)

func swap(a int, b int) {
	tmp := roomids[a]
	roomids[a] = roomids[b]
	roomids[b] = tmp
}

func RoomIdInit() {
	var i uint32
	for i = 100000; i < 1000000; i++ {
		roomids = append(roomids, i)
	}

	source := rand.NewSource(time.Now().UnixNano())
	r := rand.New(source)
	for i := 1000000 - 100000 - 1; i > 0; i-- {
		index := r.Int() % int(i)
		swap(int(i), index)
	}
}

func Delete(x uint32) {
	for j, id := range roomids {
		if id == x {
			roomids = append(roomids[:j], roomids[j+1:]...)
		}
	}
}

func GetRoomid() uint32 {
	var x uint32
	x, roomids = roomids[len(roomids)-1], roomids[:len(roomids)-1]
	return x
}

func Push(x uint32) {
	roomids = append(roomids, x)
}
