Skip to content

Random elements of AA aren't random #30875

@orlitzky

Description

@orlitzky

The AA.random_element() method only ever returns integers
among -2, -1, 0, 1, 2:

sage: ' '.join(str(AA.random_element()) for i in range(100))
2 0 0 2 1 2 -1 0 -2 -2 -2 0 -2 0 2 -1 1 0 0 1 1 -1 2 -1 0 2 1
0 0 2 1 2 0 -1 -2 -2 -1 2 -2 1 -1 -2 -2 2 -1 0 1 -1 2 2 0 -2
-1 -1 1 -2 2 0 2 -2 0 -2 1 -2 0 -2 -2 -2 -1 -2 -1 2 0 0 1 0 0
-2 0 -1 2 -2 0 -2 2 -1 -1 1 1 -2 -1 0 -2 -2 -1 2 -2 -1 -2 -2

That's a bit un-random, even by Sage standards.
A simple improvement would be to return the real part
of QQbar.random_element():

sage: [QQbar.random_element().real() for i in range(5) ]
[-5.372281323269015?,
 -0.2000000000000000?,
 0.50000000000000000?,
 -0.50000000000000000?,
 0.1906845620110298?]

Component: algebra

Author: Ben Livingston, Michael Orlitzky

Branch/Commit: 94c07ba

Reviewer: Lorenz Panny

Issue created by migration from https://trac.sagemath.org/ticket/30875

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions