Showing posts with label random. Show all posts
Showing posts with label random. Show all posts

Jan 8, 2019

Really Random Game Generator Idea

Really Random Game Generator Idea

-The Campaign's Skeleton-
Regions of Season: Roll 1d4. 
1: All of the seasons take place in the same region the characters are from
2: All the seasons take place in a region that is randomly selected
3: All the seasons take place in separate regions that are randomly selected.
4: All the missions take place in separate regions. 

-Mission 1: Takes place in Roguelandia and comprises of the following objective.
--Sting; Grade 5 sting operation.
-Mission 2: Takes place in Scorchedlandia and comprises of the following objective
– Grade 2 Rescue 
– Grade 2 Infiltrate
– Grade 5 Test
– Grade 4 Crucial Skill Check
-Mission 3: Also takes place in Icelandia and comprises of the following objectives
– Grade 4 Crucial Skill Check
– Grade 4 Repair
– Grade 4 Infiltrate
– Grade 2 Confirm

Apr 13, 2017

SQLite: showing a random record from a table

Random record

If many occasion developer want to get a random record(s) from a table, because they are programming a quizz, or a game - it turns out there is no native instructions for that in SQLite
but you can use this workaround:

SELECT
*, random() as R
FROM Table
ORDER BY R
LIMIT 1 ;

Why it works

It insert a random number (R) for each record and then using the order by there is going to be a selection of the smaller number (R)  - you can even change the LIMIT to get more than one record - let say 3

SELECT *, random() as R FROM Table ORDER BY R LIMIT 3 ;

Feb 10, 2017

Sqlite: how to generate a random number within range 0..99

Random()

The Sqlite random() function will returns a pseudo-random integer between -9223372036854775808 and +9223372036854775807.

abs() will returns the absolute value of the numeric argument

floor() or round() will return a floating-point value X rounded to Y digits to the right of the decimal point. If the Y argument is omitted, it is assumed to be 0.

NB:floor() will only work within SQLExplorer, Dbeaver, ...

Result

select floor(abs(random()/92233720368547758.07));
will generate within 0..99

and
select round(abs(random()/92233720368547758.07),0);
will generate within 1..100

Popular Posts