Solved

How to generate random int64 Postgresql?

Posted on 2012-03-28
1
744 Views
Last Modified: 2012-04-11
Hi Experts,

I want to create function to generate random int64 using Postgresql.

Any suggestion code? Thanks before.
0
Comment
Question by:jimmycdinata
1 Comment
 
LVL 22

Accepted Solution

by:
earth man2 earned 500 total points
ID: 37790211
try built in random() function gives random number between 0.0 and 1.0


select cast(9223372036854775807 *  (2.0 *(random()- 0.5))as bigint)+ case (random()> 0.5) when true then -1 else 0 end;

if you are on linux or unix the reading direct from /dev/random may be the right option using a c function.

it depends on how random your random number must be.  Often modern motherboards have white noise random number hardware it depends....
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Best database to use for Maps is PostgreSQL. This is an open source database. Comes as a package with most Linux OS. For more info visit the following site: http://www.postgresql.org/ (http://www.postgresql.org/) This requires some add-o…
Many developers have database experience, but are new to PostgreSQL. It has some truly inspiring capabilities. I have several years' experience with Microsoft's SQL Server. When I began working with MySQL, I wanted a quick-reference to MySQL (htt…
Steps to create a PostgreSQL RDS instance in the Amazon cloud. We will cover some of the default settings and show how to connect to the instance once it is up and running.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question