Unable to use math/rand and crypto/rand together

573 views
Skip to first unread message

Amee Trivedi

unread,
Dec 8, 2014, 1:58:22 PM12/8/14
to golan...@googlegroups.com
Hi,

When i try to use math/rand and crypto/rand together it gives me error.

Is there any workaround for this?

amee

Matthew Kane

unread,
Dec 8, 2014, 2:00:42 PM12/8/14
to Amee Trivedi, golang-nuts
You can import packages with different local names, e.g.:

import mrand "math/rand"
import crand "crypto/rand"
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



--
matt kane's brain
im: mkb.di...@gmail.com (gtalk) / mkbatwerk (AIM)
twitter: the_real_mkb / nynexrepublic
http://hydrogenproject.com

Jan Mercl

unread,
Dec 8, 2014, 2:01:22 PM12/8/14
to Amee Trivedi, golan...@googlegroups.com


On Mon, Dec 8, 2014, 19:58 Amee Trivedi <ameet...@gmail.com> wrote:



When i try to use math/rand and crypto/rand together it gives me error.

Is there any workaround for this?

Give your imports an explicit name:

        import name "path"

-j


David Anderson

unread,
Dec 8, 2014, 2:01:35 PM12/8/14
to Amee Trivedi, golang-nuts
You mean a way to avoid the package name conflict? Just rename one of them at import time:

import (
  "crypto/rand"
  mrand "math/rand"
)

Then refer to math/rand as mrand in your code.

- Dave


--
Reply all
Reply to author
Forward
0 new messages