Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to generate random int64 Postgresql?

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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

916 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