I'm trying to figure out a method that I could use to build a system that would assign weights to independent objects in a table for random weighted sorting - based on the importance of that item. If a scale were on 0-9, for instance. If you assigned four items 3, 5, 9, 1, then the system would be able to sort through those numbers, and build the list so that each weight adds up to 1 total between the four objects. How would you go about sorting these items?
At the moment, this is what I have for SQL:
CREATE TABLE IF NOT EXISTS `block_types` (
`ID` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`BlockTypeUID` varchar(35),
`Name` varchar(20),
`Weight` float,
`Turns` int(11),
`Score` int(11),
`Hitpoints` int(20),
`Rarity` int(11),
`Multiplier` int(1),
`Effect` int(11),
`Area` int(11),
PRIMARY KEY (`ID`)
) DEFAULT COLLATE=utf8_general_ci;
Weight is a float from 0.0001 to 1, and at the moment I'm basically assigning it manually through a simple input form. The idea is that Rarity would handle storing the 0-9, and be used to automatically calculate the new weight based on all other entries - so that the total sum of the table equaled 1.