Solved

How to generate random int64 Postgresql?

Posted on 2012-03-28
1
797 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the 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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

622 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