Macro value setting itself to 0 when it sees an 8 or 9?

Hello, I am trying to use a macro to set some random values and then set specific words based on those random values. It mostly works fine, except for some reason when it tries to get the value of 8 or 9 from a cell it gets the value 0 instead?

Here is what I have currently. I’m wondering if the error has anything to do with me setting the far ends of the scale separately to make sure they can only occur once? (and I know the low end of the scale can be overwritten by the high end, that’s by design)
also if it helps, I’m currently on version 24.2 (I am just a bit lazy about updating it)

	oSheet = ThisComponent.getcurrentcontroller.activesheet
	
	for row = 1 to 7
	 oCell = oSheet.getcellbyposition(1, row)
	 oCell.setString("")	
	next row
	
		for rown = 1 to 7
	oCell = oSheet.getcellbyposition(1, rown)
			rando = (int(rnd * 5)) + 2
			oCell.setValue(rando)
	next rown
	
	rando = (rnd * 6) + 1
	randw = int(rnd * 2)
	weak = oSheet.getcellbyposition(1, rando)
	weak.setValue(randw)
	rando = rnd * 6 + 1 
	randp = (int(rnd * 2) + 8)
	peak = oSheet.getcellbyposition( 1, rando)
	peak.setString(randp)
	dim val as integer
	dim msg as string	
	for rowb = 1 to 7
	oCell = oSheet.getcellbyposition(1, rowb)
	val = oCell.getValue()
	Select case val
		case 0, 1
			bcell = oSheet.getcellbyposition(2,rowb)
			bcell.setString("None")
		case 2, 3
			bcell = oSheet.getcellbyposition(2,rowb)
			bcell.setString("Weak")
		case 4, 5
			bcell = oSheet.getcellbyposition(2,rowb)
			bcell.setString("Moderate")
		case 6, 7
			bcell = oSheet.getcellbyposition(2,rowb)
			bcell.setString("Strong")
		case 8, 9
			bcell = oSheet.getcellbyposition(2,rowb)
			bcell.setString("Peak")
		end select
	next rowb

End Sub```

something like:

from random import randint

def two_dice_distribution(*_):
    doc = XSCRIPTCONTEXT.getDocument()
    sheet = doc.CurrentController.ActiveSheet
    kategories = "None,Weak,Moderate,Strong,Peak".split(',')
    out = [ [ (v:=randint(0,5)+randint(0,4)), kategories[v//2] ] for _ in range(7) ]
    sheet['B2:C8'].DataArray = out

Nevermind I figured out the issue

	peak.setString(randp)

needed to be changed to

   peak.setValue(randp)

thats why it was throwing a hissy fit at me