?
Solved

How to generate random int64 Postgresql?

Posted on 2012-03-28
1
Medium Priority
?
824 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 2000 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
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 you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

719 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